Bibi's DevLog ๐ค๐
[Spring] HTTP method - PUT ๋ณธ๋ฌธ
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์ ์ถ๊ฐํ๋ค.
'๐ฅ BE ๋ฐฑ์๋ > Spring ์คํ๋ง' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
AWS EC2 (Ubuntu) ์๋ฒ์ ์คํ๋ง ์ฑ ๋ฐฐํฌ ๊ณผ์ ์ ๋ฆฌ (0) | 2021.04.30 |
---|---|
[Spring Data JDBC, JPA] @Embeded๋?, @Embeded ์ฌ์ฉํ๊ธฐ (0) | 2021.04.30 |
[JPA] CrudRepository์ ๋ฉ์๋ & JpaRepository์ CrudRepository์ ์ฐจ์ด (0) | 2021.03.20 |
@RequestMapping ์ผ๋ก ์ค๋ณตURL ์ ๊ฑฐํ๊ธฐ (0) | 2021.03.17 |
[Spring, H2 database] ์คํ๋ง ์ฑ๊ณผ H2 ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐํ๊ธฐ (0) | 2021.03.15 |