SpringBoot的DELETE请求报错问题

又是因为版本问题。我的版本是SpringBoot的DELETE请求报错问题
前端通过DELETE请求传给控制层。
SpringBoot的DELETE请求报错问题
SpringBoot的DELETE请求报错问题
结果报错:
SpringBoot的DELETE请求报错问题

SpringBoot的DELETE请求报错问题
错误原因为:
Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘POST’ not supported]

参考原因:浏览器form表单只支持GET与POST请求,而DELETE、PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET、POST、PUT与DELETE请求,该过滤器为HiddenHttpMethodFilter。
逮到源码:默认关闭
SpringBoot的DELETE请求报错问题
所以只需要在配置文件中开启即可:spring.mvc.hiddenmethod.filter.enabled=true
SpringBoot的DELETE请求报错问题
再次运行:成功执行了DELETE请求
SpringBoot的DELETE请求报错问题
好坑大家踩。
SpringBoot的DELETE请求报错问题