最近项目组有人问我,“springboot怎么接受不到前端提交的PUT和DELETE请求?”
因而有了这篇文章,本篇文章主要解决两个问题:前端
问题1解决方案:
在ajax中发送POST请求,带上_method参数,_method值为PUT或者DELETE
实例:java
$.ajax({ url:"", type:"POST", data:{ _method:"PUT" }, success:function(data){...} })
问题2解决方案:
配置HiddenHttpMethodFilter
实例:ajax
@Configuration public class HttpRequestConfig { @Bean public HiddenHttpMethodFilter hiddenHttpMethodFilter() { HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter(); hiddenHttpMethodFilter.setBeanName("HiddenHttpMethodFilter"); hiddenHttpMethodFilter.setMethodParam("_method"); return hiddenHttpMethodFilter; } }