SpringMVC对DELETE、PUT请求的支持
1.web.xml配置FormContentFilter,即可支持DELETE和PUT请求
<!--支持PUT请求和DELETE请求-->
<filter>
<filter-name>formContentFilter</filter-name>
<filter-class>org.springframework.web.filter.FormContentFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>formContentFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.前端使用ajax进行请求时直接指定请求的type为delete或者put即可,不需要表单额外提供特殊的域,例
$.ajax({
type:'delete',
url:'/topic/user/'+data[0].id,//data[0].id路径变量,指定需要删除的用户id
contentType:'application/json',
success:function (da) {
if (da == 0) {
layer.msg("删除失败");
}
else {
layer.msg("删除成功");
userIns(); //重载用户信息表格
}
}
});
处理该请求的Controller方法
@DeleteMapping("/user/{id}")
public int deleteUser(@PathVariable("id") int id){
//调用service删除指定id的用户信息
return userInfoService.deleteUser(id);
}