spring mvc怎么接收list
1个回答
展开全部
1.表单提交前,表单序列化JSON格式传台,解析封装List.
2.我创建UserModel
public class UserModel {
private List users;
public List getUsers() {
return users;
}
public void setUsers(List users) {
this.users = users;
}
public UserModel(List users) {
super();
this.users = users;
}
public UserModel() {
super();
}
}
修改我控制层页面
1 @RequestMapping("/user")
2 public void test(UserModel userModel ){
3 logger.debug(JSONArray.toJSON(userModel));
4 }
<%@ page language="java" import="java.util.*" pageEncoding="UTF
-8"%>
用户名:<input type="text" name="users
[0].username">
密码:<input type="text" name="users
[0].password">
用户名:<input type="text" name="users
[1].username">
密码:<input type="text" name="users
[1].password">
2.我创建UserModel
public class UserModel {
private List users;
public List getUsers() {
return users;
}
public void setUsers(List users) {
this.users = users;
}
public UserModel(List users) {
super();
this.users = users;
}
public UserModel() {
super();
}
}
修改我控制层页面
1 @RequestMapping("/user")
2 public void test(UserModel userModel ){
3 logger.debug(JSONArray.toJSON(userModel));
4 }
<%@ page language="java" import="java.util.*" pageEncoding="UTF
-8"%>
用户名:<input type="text" name="users
[0].username">
密码:<input type="text" name="users
[0].password">
用户名:<input type="text" name="users
[1].username">
密码:<input type="text" name="users
[1].password">
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询