Dev/Thymleaf
checkbox 로 데이터 넘기기
린네의
2024. 3. 9. 17:33
thymleaf 에서 checkbox 를 사용해서 데이터를 넘기는 방법은 다음과 같다.
- front 예제
<li class="list-group-item" th:each="material : ${materials}">
<input type="checkbox" th:field="*{materialIds}" th:value="${material.id}" autocomplete="off">
<label class="btn" th:for="${#ids.prev('materialIds')}" th:text="${material.name}"></label>
</li>
#ids.prev 관련글은 여기를 참고해주면 된다.
서버에서 받을때는 String 형식으로 오기 때문에 List<String> 으로 받아오게 하면 된다.