JavaSpringMVC多行表单提交提交新的ModelAttribute
好的,这是spring的null ModelAttribute的另一个特性,但是我已经尝试了我找到的所有东西,但是都不起作用
我已经将此教程功能添加到我的web应用程序中spring-mvc除了必须将数据从表单返回到我的bean时,其他一切都非常有效
我使用两种post方法
@RequestMapping(method = RequestMethod.POST)
public String openEdit(@RequestParam("notfound") String[] notFound,
Model model){
EditForm editForm = editModel.createEditForm(notFound);
model.addAttribute("editForm",editForm);
return "Edit/EditOwners";
}
@RequestMapping(method = RequestMethod.POST,value = "/saveOwners")
public String saveOwners(@ModelAttribute("editForm") EditForm editForm){
editModel.addOwners(editForm);
return "index";
}
第一个运行良好,我可以在Jsp中看到数据,第二个获得一个新的ModelAttribute
这是我的表格
<form:form method="POST" action="saveOwners" modelAttribute="editForm" >
<table class="table table-bordered table-striped table-hover table-condensed">
<caption>
<h4>Edit The Owners</h4>
</caption>
<thead>
<tr>
<td>Name</td>
</tr>
</thead>
<tbody>
<c:forEach items="${editForm.owners}" var="item" varStatus="status">
<tr>
<td>${item.name}</td>
<td><input type="text" name="${owners[status.index].outId}" value="${item.outId}" /> </td>
<td><input type="text" name="${owners[status.index].type}" value="${item.type}" /> </td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="submit" value="Save" class="btn btn-primary"/>
</form:form>
这里怎么了?PS我尝试了我的输入,有类型属性和没有类型属性,但它仍然为空,正如我说的,我可以看到我的数据,但我不能提交它们
# 1 楼答案
您是否尝试将以下注释添加到控制器类的顶部