๐ฅ BE ๋ฐฑ์๋/Spring ์คํ๋ง
[Spring] HTTP method - PUT
๋น๋น bibi
2021. 4. 6. 00:18
PUT method
POST๋ก๋ ํ์์ ๋ณด ์์ ์ ๊ฐ๋ฅํ์ง๋ง, PUT ์ ์ฌ์ฉํด ์์ฒญ์ ๋ช ํํ ํ๋ ๊ฒ์ด RestAPI๊ด์ ์์ ๋ ๋ฐ๋์งํ๋ค.
POST ๋์ PUT method๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
์์ ํ๋ฉด(
updateForm.html
)์์ ์์ ๋ ๊ฐ์ ์ ์กํ ๋ PUT๊ฐ์ ๋ค์๊ณผ ๊ฐ์ด hidden์ผ๋ก ์ ์กํ๋ค.<input type="hidden" name="_method" value="PUT" />
์ form ์ฌ๋ ํ๊ทธ ์๋์ ๋ฃ๋๋ค.โ
<form>
์ method๋ฅผ put์ผ๋ก ๋ฐ๊พธ์ด์๋ ์ ๋๋ค!form์ get/post๋ง ์ง์ํ๊ธฐ ๋๋ฌธ.
updateForm.html
<form name="question" method="post" action="/user/{{id}}"> <input type="hidden" name="_method" value="PUT" /> // ... </form>
์์ ๊ฐ์ด
_method
๋ก PUT์ ์ ๋ฌํ๋ฉด UserController์์๋@PutMapping
์ผ๋ก URL์ ๋งคํํ ์ ์๋ค.
PUT ๋ฉ์๋ ์ค๋ฅ์ ํด๊ฒฐ๋ฐฉ์
spring.mvc.hiddenmethod.filter.enabled=true
์ ๋ด์ฉ์ application.properties์ ์ถ๊ฐํ๋ค.