Thymeleaf 맛보기

Drumj·2022년 11월 25일
0

오늘의 학습

타임리프 - 스프링 통합 강의를 들으면서 처음 본 거 정리.

th:object 사용법

<form action="item.html" th:action th:object="${item}" method="post">
<input type="text" id="itemName" name="itemName" th:field="*{itemName}" class="form-control" placeholder="이름을 입력하세요">

th:object에 ${item}을 넣으면 그 아래에서 th:field를 사용할 때 *{itemName}이라 하면
알아서 ${item.itmeName} 으로 인식한다. 또 field를 사용해서 id, name에 알아서 itemName을 넣어주기 때문에 위 코드에서 id와 name 을 없애도 된다!

<input type="text" th:field="*{itemName}" class="form-control" placeholder="이름을 입력하세요">

또 {itemName}에 값이 있으면 값도 출력해준다! value로 출력

th:field를 사용하면 id, name , value 를 한번에 처리!!
와~ 대박~

CheckBox에서의 활약

체크박스에서 th:field를 사용하게 되면 <input type="hidden">까지 만들어 준다!!
미친 성능의 타임리프...

아니 이게 뭔일이고... checked 까지 해준다고???
지 혼자 다 해주네 물건이다 물건!

0개의 댓글