大佬教程收集整理的这篇文章主要介绍了清单 使用Spring 3 MVC作为表单支持对象,正确的语法?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
也许这回答了您的问题:
@Controller("/")
public class FooController{
//returns the modelattribute fooListWrapper with the vIEw fooForm
@requestMapPing(value = "/FOO", method = requestMethod.GET)
public String getFooForm(Model model) {
FooListWrapper fooListWrapper = new FooListWrapper();
fooListWrapper.add(new Foo());
fooListWrapper.add(new Foo());
//add as many FOO you need
model.addAttribute("fooListWrapper", fooListWrapper);
return "fooForm";
}
@requestMapPing(value = "/FOO", method = requestMethod.POST)
public String postFooList(@modelattribute("fooListWrapper")FooListWrapper fooListWrapper, Model model) {
//...........
}
}
public class FooListWrapper {
private List<Foo> fooList;
public FooListWrapper() {
this.fooList = new ArrayList<Foo>();
}
public List<Foo> getFooList() {
return fooList;
}
public voID setFooList(List<Foo> fooList) {
this.fooList = fooList;
}
public voID add(Foo foo) {
this.fooList.add(foo);
}
}
public class Foo {
private String name;
public Foo() {
}
public String getname() {
return name;
}
public voID setname(String Name) {
this.name = name;
}
}
<c:url var="fooUrl" value="/FOO"/>
<form:form ID="frmFoo" action="${fooUrl}" method="POST" modelattribute="fooListWrapper">
<c:forEach items="${fooListWrapper.fooList}" varStatus="i">
<form:input path="fooList[${i.index}].name" type="text"/>
</c:forEach>
<button>submit</button>
</form:form>
我想做这样的事情,哪里Foo
是一个具有一个String字段名称和getter / setter的类:
<form:form id="frmFoo" modelAttribute="foos">
<c:forEach items="${foos}" var="foo">
<form:input path="${foo.namE}" type="text"/>
然后提交名称完整的Foos完整列表?
我的控制器如下所示:
@requestMapping(value = "/FOO",method = requestMethod.POST)
public String getSendEmail(List<Foo> foos,Model model) {
// ...
}
以上是大佬教程为你收集整理的清单 使用Spring 3 MVC作为表单支持对象,正确的语法?全部内容,希望文章能够帮你解决清单 使用Spring 3 MVC作为表单支持对象,正确的语法?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。