본문 바로가기

프로그래밍/Spring & MyBatis

[Thymeleaf]타임리프 if else if else 조건식, 3항 연산자 사용법

타임리프 if else if else 조건식, 3항 연산자 사용법


<h2 th:text="${potentially_complex_expression} ? 'Hello' : 'Something else'">/h2>


<div th:switch="${user.role}"> 
<p th:case="'admin'">User is an administrator</p>
<p th:case="#{roles.manager}">User is a manager</p>
<p th:case="*">User is some other thing</p> 
</div>


<div th:with="condition=${potentially_complex_expression}" th:remove="tag">
<h2 th:if="${condition}">Hello!</h2>
<span th:unless="${condition}" class="xxx">Something else</span>
</div>