使用ajax直接发送put请求:
封装的数据
Employ
[empId=100, empName=null, gender=null, email=null]
问题:
请求体中有数据,
但是Employee对象封装不上;
update tbl_emp where emp_id = 1024;
原因:
Tomcat:
1.将请求体中的数据,封装一个map。
2.requestParameter(“empName”)就会从这个map中取值
3.SpringMVC封装POJO对象的时候,会把POJO中每个属性的值,request.getParameter(“email”);
AJAX发送PUT请求时:
PUT请求:请求体中的数据,request.getParameter(“empName”)拿不到
Tomcat一看是PUT不会封装请求体中的数据为map,只有POST形式的请求才封装请求体为map
解决方法:
方法一:发送POST请求,在请求体中加上method字段
1 | $.ajax({ |
方法二:web.xml中添加过滤器,HttpPutFormContentFilter可以将请求体中的数据重新封装
1 | <!-- 解决ajax发送put请求,实体封装失败问题 --> |