[Thymeleaf] form 태그의 post

@t189216·2024년 3월 20일

💥 트러블 슈팅

목록 보기
6/8
...
<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 등을 사용해야 한다.

비동기 통신 라이브러리 종류

profile
Today I Learned

0개의 댓글