[Spring Boot] 제어문 처리

    3.2.2 제어문 처리

     

    타임리프의 제어문 처리

    • th:if ~ unless 
    • 삼항 연산자 스타일

     

     

    th:if ~ unless

        <li th:each = "dto, state : ${list}">
           <span th:if="${dto.sno % 5 == 0}" th:text="${'----------------'+dto.sno}"></span>
           <span th:unless="${dto.sno % 5== 0}" th:text="${dto.first}"></span>
        </li>

     

    실행 결과

     

    삼항 연산자를 사용하는 방법 

    <ul>
        <li th:each = "dto, state : ${list}" th:text="${dto.sno % 5 == 0}?${dto.sno}">
        </li>
    </ul>

     

    실행 결과

     

    응용

     

    728x90

    댓글