在學習 Spring Boot 過程中,在實現 restful 的更新操作時,需要將表單數據以 PUT 方法提交。
按照視頻中操作,直接在表單中添加
<input type="hidden" name="_method" value="put" />
語句后,再次提交時,依然是使用 POST 方法。
原因是在 Spring Boot 的 META-INF/spring-configuration-metadata.json 配置文件中
默認是關閉 Spring 的 hiddenmethod 過濾器的。
所以直接在表單提交的數據中添加 "_method" 數據並不起作用。
解決辦法就是在 Spring Boot 的配置文件 application.properties 中將 hiddenmethod 過濾器設置為啟用即可。
# 啟用hiddenMethod過濾器 spring.mvc.hiddenmethod.filter.enabled=true