public class UserEntity implements java.io.Serializable {
private static final long serialVersionUID = 1168696728446841996L;
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
- UserEntityVO .java定义了一个包含List的实体类,springmvc不能直接用List作为形参接收List
public class UserEntityVO {
private List<UserEntity> userList;
public List<UserEntity> getUserList() {
return userList;
}
public void setUserList(List<UserEntity> userList) {
this.userList = userList;
}
}
public String update(UserEntityVO entity) {
List<UserEntity> list = entity.getUserList();
return null;
}
- 页面定义:注意表单提交时input框的name属性的命名一定要注意格式
<form action="user/update" method="post">
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th><button type="submit" >更新</button></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="userList[0].name"/></td>
<td><input type="text" name="userList[0].age"/></td>
</tr>
<tr>
<td><input type="text" name="userList[1].name"/></td>
<td><input type="text" name="userList[1].age"/></td>
</tr>
</tbody>
</table>
</form>
- springmvc控制层接收数组
- 方法的形参定义一个数组:例如array
- 页面input传递时name属性的命名和形参中的命名保持一致