springmvc请求参数绑定集合类型
Account.java
public class Account implements Serializable { private String username; private String password; private Double money; private List<User> list; private Map<String,User> map;
param.jsp
<form action="param/saveAccount" method="post"> 姓名:<input type="text" name="username" /><br> 密码:<input type="text" name="password" /><br> 金额:<input type="text" name="money" /><br> user姓名:<input type="text" name="list[0].name" /><br> user年龄:<input type="text" name="list[0].age" /><br> user姓名:<input type="text" name="map['one'].name" /><br> user年龄:<input type="text" name="map['one'].age" /><br> <input type="submit" value="提交"> </form>
@RequestMapping("/saveAccount") public String testSaveAccount(Account account) { System.out.println("执行了..."); System.out.println("account:"+account); return "success"; }account:Account{username='阿花', password='123', money=1000.0, list=[User{name='阿虎', age=21}], map={one=User{name='阿来', age=29}}}