본문 바로가기
IT/Thymeleaf

[Thymeleaf] - 타임리프 셀렉트박스 반복문 처리 th:with, th:unless, #numbers.sequence 날짜(시간, 분) 선택하는 법

by 차이나는 개발자 2022. 1. 29.
728x90
반응형

#타임리프 셀렉트박스 반복문 처리 th:with, th:unless,  #numbers.sequence 날짜(시간, 분) 선택하는 법

 

 

#th:with, th:unless, #numbers.sequence

 

// 방법1
<select id="startHour" name="startHour">
  <th:block th:each="num : ${#numbers.sequence(0,23)}">
    <th:block th:with="hour = ${num <= 9 ? '0'+num : num}">
      <th:block th:with="bgnHour = ${data.bgnHour <= 9 ? '0'+data.bgnHour : data.bgnHour}">
        <option th:value="${hour}" th:text="${hour}+시" th:selected="${hour eq bngHour}"></option>
      </th:block>
    </th:block>
  </th:block>
</select>

// 방법2
<select id="startHour" name="startHour">
  <th:block th:each=" i : ${#numbers.sequence(0, 23)}">
    <th:block th:if="${i < 10}">
      <option th:value="|0${i}|" th:text="|0${i}시|"></option>
    </th:block>
    <th:block th:unless="${i < 10}">
      <option th:value="${i}" th:text="|${i}시|"></option>
    </th:block>
  </th:block>
</select>

 

 

 

728x90
반응형

댓글