玩:是否可以提取表单数据而不将其绑定到模型? [英] Play: Is it possible to extract form data without binding it to a model?

查看:73
本文介绍了玩:是否可以提取表单数据而不将其绑定到模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我正试图从表单POST请求中提取各个表单字段的信息,我以为会是这样.这是一个例子:

At the moment I'm trying to extract information of individual form fields from form POST requests, & I thought it would be something like this. Here's an exmaple:

在HTML中

<form action="..." method="POST">
    <input name="field-name">
    <input type="submit">
</form>

并从Controller获取信息:

And to get the information from the Controller:

String field = Form.form.get('field-name');

我一直在搜索文档,发现的所有示例都在将请求绑定到模型类,该类生成模型.在某些情况下,我不想这样做,因为我想拉开单个字段并处理数据.

I've been searching the docs, and all the examples I've found have been binding a request to a model class, which generates a model. I don't want to this in a few cases, as I want to pull the indivisual fields and manipulate the data.

更正了一些深夜拼写错误

edit: corrected some late night spelling errors

推荐答案

您可以使用

You can use a DynamicForm to get fields by name in a controller.

DynamicForm form = form().bindFromRequest();
String fieldValue = form.get("field-name");

或更短:

String name = form().bindFromRequest().get("field-name");

这篇关于玩:是否可以提取表单数据而不将其绑定到模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆