今天,我在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}"