spring mvc 如何从前台表单传递集合参数并绑定集合对象。

NewMoons NewMoons 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Public class Person{
private String username;

private String int age;

set,get.......
}


记得用Struts2的时候页面表单这样
<form id="form" action="test/test.do" method="post">
<input type="text" name="persons.username[0]" value="jobs"/>
<input type="text" name="persons.age[0]" value="55"/><br/>
<input type="text" name="persons.username[1]" value="jim"/>
<input type="text" name="persons.age[1]" value="21"/><br/>
<input type="submit">
<form>
然后Action类的属性里可以通过ArrayList<Person> persons直接接收(或者叫装配注入)

但在Springmvc的控制层方法里这样无法接收,尝试了很多写法都不行
@ModelAttribute(value = "persons") ArrayList<Person> persons

求解,谢谢!
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
NewMoons
Web 开发 81,108 成员 341,721 内容