绑定一个数组
<form action="param-bind-array.action" method="post">
<input type="checkbox" name="enjoy" value="1">LOL
<input type="checkbox" name="enjoy" value="2">DNF
<input type="checkbox" name="enjoy" value="3">CF
<input type="checkbox" name="enjoy" value="4">DOTA
<input type="checkbox" name="enjoy" value="5">WOW
<P>
<input type="submit" value="走你">
</P>
</form>
@RequestMapping("/param-bind-array")
@ResponseBody //使用数组接收
public String paramBindArray(int [] enjoy){ return Arrays.toString(enjoy); }
复杂参数绑定
<form action="param-bind-vo.action" method="post">
<hgroup>
学科名称:<input type="text" name="subjects[0].subjectname"><br/>
学科描述:<input type="text" name="subjects[0].subjectdesc"><br/>
</hgroup>
<hgroup>
学科名称:<input type="text" name="subjects[1].subjectname"><br/>
学科描述:<input type="text" name="subjects[1].subjectdesc"><br/>
</hgroup>
<hgroup>
学科名称:<input type="text" name="subjects[2].subjectname"><br/>
学科描述:<input type="text" name="subjects[2].subjectdesc"><br/>
</hgroup>
<p>
<input type="submit" value="提交">
</p>
</form>
额外定义一个用于接收参数的类
public class SubjectVO {
//当然也可以有其他的属性
//必须有一个集合
private List<Subject> subjects;
public List<Subject> getSubjects() { return subjects; }
public void setSubjects(List<Subject> subjects) { this.subjects = subjects; }
}
后端控制器
@RequestMapping("/param-bind-vo")
@ResponseBody //使用VO对象接收
public SubjectVO paramBindVo(SubjectVO subjectVO){ return subjectVO; }