今天,我在Spring Boot中使用put和delete请求方式时,遇到Request method DELETE not supported的问题,很是头疼,仔细检查代码没发现什么错误。直到用以下方式解决。
我的Spring Boot版本是2.2.2,开始我没有注意它和1.x的区别。
最新版本的spring boot 默认不开启 restful 分割api
@Bean
@ConditionalOnMissingBean({HiddenHttpMethodFilter.class})
@ConditionalOnProperty(
prefix = "spring.mvc.hiddenmethod.filter",
name = {"enabled"},
matchIfMissing = false
)
开启方式:
# 启用hiddenMethod过滤器
spring.mvc.hiddenmethod.filter.enabled=true
通过自定义属性传递参数:
th:attr="del_uri=@{/emp/}+${emp.id}"