首頁  >  文章  >  Java  >  Springboot使用put、delete請求報錯405怎麼解決

Springboot使用put、delete請求報錯405怎麼解決

WBOY
WBOY轉載
2023-05-11 18:01:113002瀏覽

Springboot使用put、delete請求報錯

SpringBoot給我們自動配置好了HiddenHttpMethodFilter,但是最近發現好像用不了,我用的是SpringBoot版本是2.2.2,預設配置被改成了false ,也就是關閉了自動配置,不知道sprongboot什麼鬼,坑! ! !

There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported
org.springframework.web.HttpRequestMethodNotSupportedsupported

org.springframework.web.HttpRequestMethodNotSupportedException: Request method ' POST' not supported

要把springboot設定yml檔案改成

spring:
  mvc:
   hiddenmethod:
      filter:
        enabled: true

Springboot錯誤提示405狀態

一、錯誤提示405狀態截圖

Springboot使用put、delete請求報錯405怎麼解決

二、405狀態的原因

SpringBoot的自動配置中預設是關閉spring.mvc.hiddenmethod.filter 過濾器的,所以當我們提交的資料是PUT、POST、DELETE方式時,我們使用的_method

並不起作用。

Springboot使用put、delete請求報錯405怎麼解決

spring.mvc.hiddenmethod.filter 自動設定:

Springboot使用put、delete請求報錯405怎麼解決

三、解決方法

#在Spring Boot 的設定檔application.properties 中將hiddenmethod.filter 過濾器設定為啟用即可。 ###
spring.mvc.hiddenmethod.filter.enabled=true

以上是Springboot使用put、delete請求報錯405怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除