以前用struts2时,url请求参数自动封装成对象用的很是爽,但是在spring中,就有问题了:
比如,有两个对象
[code="java"]class Student{
private String name;
private String type; //比如有自费、公费
}
[/code]
[code="java"]class teacher{
private String name;
private String level;
}[/code]
当中的get/set方法省略。
struts2的中jsp的写法是:
[code="java"]
<input name="student.name" value="Kate" />
<input name="student.type" value="自费" />
<input name="teacher.name" value="Gavin" />
<input name="teacher.level" value="2" />
[/code]这样子在action中就能封装好student和teacher对象。
但是在spring中,要这么写
[code="java"]@RequestMapping("/school.do")
public String school(Student student, Teacher teacher) {
return "school";
}[/code]
如果还是想刚才的jsp那些写表单,是不能封装参数的,必须把“student.”和“teacher.”去掉,但是这样封装就不能准确封装了。