[Thymeleaf] checkbox | list안에 있는 값만 check 하기

장수현·2021년 10월 13일
0

에어비앤비

목록 보기
9/15

숙소의 편의시설 리스트를 수정할 때 기존 체크리스트를 수정폼에서 똑같이 체크된 상태로 보여주기 위한 방법을 찾다가 아주 유용하고 간단한 방법을 찾았다.

th:field와 th:value를 같이 작성하면 타임리프가 자동으로 두 값을 비교해 checked 설정을 해준다.

<label th:each="facilite : ${facilites}">
	<input type="checkbox" name="facilities" th:field="*{home.facilities}" th:value="${facilite.id}">
    	<span th:text="${facilite.name}"></span>
</label>

도움 받았던 글
https://catsbi.oopy.io/81398571-33b8-471f-8191-ca7415b86326

0개의 댓글