1、实体类
package beans;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public class Collerction implements Serializable {
private List<User> list;
private Map<String,User> map;
public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public Map<String, User> getMap() {
return map;
}
public void setMap(Map<String, User> map) {
this.map = map;
}
@Override
public String toString() {
return "Collerction{" +
"list=" + list +
", map=" + map +
'}';
}
}
2、jsp页面********
list在声明的时候以中括号内声明第几个user元素
map类在中括号内单引号声明key值
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>hello</title>
</head>
<body>
<h1>绑定参数</h1>
<%--封装list和map--%>
<form action="/param2/test3" method="post">
list姓名:<input type="text" name="list[0].username"><br>
list年龄:<input type="text" name="list[0].age"><br>
map姓名:<input type="text" name="map['one'].username"><br>
map年龄:<input type="text" name="map['one'].age"><br>
<input type="submit" value="猛击此处提交">
</form>
</body>
</html>
3、controller类
package controller;
import beans.Collerction;
import beans.Info;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/param2")
public class ParamController2 {
@RequestMapping("/test3")
public String save2(Collerction collerction){
System.out.println(collerction);
return "success";
}
}