后台获取前台表单数据方法
1. 利用ServletRequestDataBinder对象进行表单数据的绑定
public ModelAndView validateUser(HttpServletRequest httpRequest,HttpServletResponse httpResponse) throws Exception {
UserInfo user=new UserInfo();
ServletRequestDataBinder binder =new ServletRequestDataBinder(user);
binder.bind(httpRequest);
System.out.println(user.getLoginName());
return null;
}
2.使用@requestBody注解绑定表单数据
引入https://github.com/marioizquierdo/jquery.serializeJSON 的js方法
$('#formId').serializeJSON( );
在ajax请求中通过JSON.stringify( )设置data参数为json字符串