Qual é a melhor maneira de fazer um simples if- elseno Thymeleaf?
Quero alcançar no Thymeleaf o mesmo efeito que
<c:choose>
<c:when test="${potentially_complex_expression}">
<h2>Hello!</h2>
</c:when>
<c:otherwise>
<span class="xxx">Something else</span>
</c:otherwise>
</c:choose>
em JSTL.
O que eu descobri até agora:
<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>
Não quero avaliar potentially_complex_expressionduas vezes. Por isso, introduzi a variável local condition. Ainda não gosto de usar ambos th:if="${condition}e th:unless="${condition}".
Uma coisa importante é que eu uso duas tags HTML diferentes: digamos h2e span.
Você pode sugerir uma maneira melhor de conseguir isso?