我在jsp里这样定义
method="post">
在提交后会访问下面的controller
@RequestMapping(params = "action=doLogon", method = RequestMethod.POST)
public ModelAndView doLogon(MemberForm form, HttpServletRequest request, HttpServletResponse response) throws NotLogonException {
String logonEmail = form.getEmail();
String password = form.getPassword();
}
MemberForm是一个POJO里面有email,password,等等一些属性
现在问题是spring的form标签的值绑定是如何进行的?也就是说,为什么我在doLogon方法里能使用form.getEmail();获得jsp提交的表单里的值。dispatcherservlet是如何执行这个步骤的。我想知道一下原理
PS:代码比较简陋,但大概的意思我想我叙述清楚了,谢谢大家了
我举个例子:
[code="java"]Object entity = context.getClassLoader().loadClass(
"com.icom.ud.domain." + name.toUpperCase()).newInstance();
// 数据绑定,spring提供了很好的工具。
ServletRequestDataBinder binder = new ServletRequestDataBinder(
entity);
binder.bind(request);[/code]
可以通过反射获取 方法参数类型数组,有了class,通过以上方式就可以绑定到参数上了。
参数如果是对象,必须可以用newInstance来实例化对象。
到底 应该就是java反射来给属性(域)赋值了。