1.jsp页面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test here</title>
</head>
<body>
<form method="post" action="testAdd" id="form">
<input type="text" name="users[0].id"/>
<input type="text" name="users[0].password"/>
<input type="text" name="users[1].id"/>
<input type="text" name="users[1].password"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
2. 创建两个对象
(1)
package com.lucene.model;
public class User {
private Integer id;
private String username;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
(2)
package com.lucene.model;
import java.util.List;
public class UserModel {
private List<User> users;
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
}
3.创建控制器
@RequestMapping(value = "/testAdd", method ={RequestMethod.POST})
public String testAdd(UserModel userModel) {
return "test";
}
4.关键点,list 必须是在一个对象里面,然后users[0].username的users 就是对象里面的list的变量。