Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从SpringMVC方法控制器检索表单中插入的数据?_Spring_Spring Mvc_Thymeleaf - Fatal编程技术网

如何从SpringMVC方法控制器检索表单中插入的数据?

如何从SpringMVC方法控制器检索表单中插入的数据?,spring,spring-mvc,thymeleaf,Spring,Spring Mvc,Thymeleaf,我是SpringMVC的新手,我正在开发一个SpringMVC应用程序,它使用Thymeleaf作为视图技术 因此,在这个视图中,我有一个绑定到模型对象的表单,如下所示: <form id="datiAinmatoreDigitale" th:object="${datiAnimatoreForm}" method="post" th:action="@{/salvaDatiAnagraficiAD}"> <div class="row text-left rigaNo

我是SpringMVC的新手,我正在开发一个SpringMVC应用程序,它使用Thymeleaf作为视图技术

因此,在这个视图中,我有一个绑定到模型对象的表单,如下所示:

<form id="datiAinmatoreDigitale" th:object="${datiAnimatoreForm}" method="post" th:action="@{/salvaDatiAnagraficiAD}">
    <div class="row text-left rigaNominaAnimatoreDigitale">
        <div class="col-md-4 leftAlligned">
            <label for="nomeAD">Nome docente:</label>
        </div>

        <div class="col-md-8 leftAlligned">
            <input id="nomeAD" class="form-control" type="text" th:field="*{nome}"/>
        </div>
   </div>

   .............................................................
   .............................................................
   .............................................................
   SOME OTHER FIELDS
   .............................................................
   .............................................................
   .............................................................

   <button type="submit" class="btn btn-default" style="color: #0F8BB0; margin-right: 10px;">Save</button>
</form> 
好的,它可以工作,我在提交表单时正确地输入了这个salvaDatiAnagraficiAD()方法

现在我的问题是:如何从我的salvaDatiAnagraficiAD()controller方法检索插入到上一个表单中的数据

我试图实现类似的东西(基于我项目中找到的一些代码),但它无法工作(引发了一个异常,因此我认为这不是正确的方法):


我错过了什么?如何正确检索插入到表单中的数据并将这些数据放入AnimatoreForm对象中?

您可以将注释@RequestParam与方法signutare中的映射对象一起使用。 比如:

在你的例子中是

params.get("nome");
另一个选项是,在控制器方法签名中使用表单中的对象

@RequestMapping(value = "/salvaDatiAnagraficiAD", method = RequestMethod.POST)
public String salvaDatiAnagraficiAD(AnimatoreForm datiAnimatoreForm, HttpServletRequest request, Model model, Locale locale) throws JsonParseException, JsonMappingException, IOException {
    return null;
}
因此,可以使用对象访问输入字段

datiAnimatoreForm.getNome();

在移动设备上,但是看看
@modeldattribute
,它为您完成所有解析,并将完整的POJO作为方法参数注入。
params.get("input-name");
params.get("nome");
@RequestMapping(value = "/salvaDatiAnagraficiAD", method = RequestMethod.POST)
public String salvaDatiAnagraficiAD(AnimatoreForm datiAnimatoreForm, HttpServletRequest request, Model model, Locale locale) throws JsonParseException, JsonMappingException, IOException {
    return null;
}
datiAnimatoreForm.getNome();