解决
前端:在Ajax中发送POST
求后,带_method
参数,将其修改为PUT
,或者DELETE
请求
后台:配置HiddenHttpMethodFilter
前端代码
$.ajax({
url:home + "/user/update",
type:"POST",
data:{id :id ,
_method:"PUT"},
success:function(result){
alert("update success");
}
});
springboot
配置bean
@Configuration
public class HttpRequestConfig {
@Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();
hiddenHttpMethodFilter.setBeanName("HiddenHttpMethodFilter");
hiddenHttpMethodFilter.setMethodParam("_method");
return hiddenHttpMethodFilter;
}
}
参考:https://www.cnblogs.com/xy-ouyang/articles/10648056.html?tdsourcetag=s_pctim_aiomsg