action th:action 의 값을 비워두면 현재 접속한 URL 경로가 form의 전송대상이 된다.<form th:action th:object="${form}" method="post">
<aside> 💡 form 전송 시 URL의 상태 변화 /boards/post → /boards/post
</aside>
th:field 속성 사용th:field 를 사용하면 th:object에 대입한 객체(=${form})에서 필드를 가져와 input 태그에 등록할 수 있다.
*{필드명} 으로 사용할 수 있으며 타임리프가 서버 렌더링 시 name="필드명" id="필드명" value="필드값"이 자동으로 추가되고 객체의 필드 값이 없는 경우 value 만 추가된다.
렌더링 전
<form th:action th:object="${form}" method="post">
<label for="title">제목</label>
<input type="text" th:field="*{title}" id="title">
</form>
렌더링 후
<form action method="post">
<label for="title">제목</label>
<input type="text" name="title" id="title" value>
</form>
th:errors 속성 사용타임리프는 스프링의 BindingResult 를 활용해서 편리하게 검증 오류를 표현하는 기능을 제공한다.
th:errors="*{필드}" 는 해당 필드에 오류가 있는 경우 태그를 출력한다.