...
<body>
<div class="container position-absolute top-50 start-50 translate-middle">
<div class="d-grid gap-2 col-6 mx-auto">
<form method="put" th:action="@{/todo}" th:object="${todoDto}">
<fieldset>
<legend class="text-center">수정</legend>
<div>
<br>
....
@PostMapping("/todos/{id}")
public String update(@PathVariable Long id, @ModelAttribute("todoDto") TodoDto todoDto) {
if (id != null)
todoService.update(id, todoDto.getContent(), todoDto.getDeadline());
return "redirect:/todo";
}
수정 버튼을 클릭하면 GET 매핑을 받을 수 없다고 출력된다.
HTML form 태그가 GET, POST 방식밖에 지원하지 않는다. put을 POST로 변경하자.
put을 사용하고 싶다면 비동기 통신인 AJAX, fetch, Axios 등을 사용해야 한다.