서버/Spring boot
#HiddenHttpMethodFilter
paran21
2022. 1. 24. 17:51
- HTML은 POST, GET 방식의 요청만 지원
- Spring은 POST, GET 방식을 이용해 PUT과 DELETE 방식을 사용할 수 있는 기능을 지원
설정
- application.properties
spring.mvc.hiddenmethod.filter.enabled=true
사용 방법
//게시글 삭제하기
@DeleteMapping("/post/{id}")
public String delete(@PathVariable("id") Long id) {
boardService.deletePost(id);
return "redirect:/";
}
<form id="delete-form" th:action="@{'/post/' + ${boardDto.id}}" method="post">
<input type="hidden" name="_method" value="delete"/>
<button id="delete-btn">삭제</button>
</form>