ifThymeleafで簡単に行うための最良の方法は何elseですか?
Thymeleafでと同じ効果を達成したい
<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>
JSTLで。
私がこれまでに考えたこと:
<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>
二度評価したくないpotentially_complex_expression。そのため、ローカル変数を導入しましconditionた。th:if="${condition}それでも私はとの両方を使うのは好きではありませんth:unless="${condition}"。
重要なことは、2つの異なるHTMLタグを使用することです。たとえばh2、とspan。
それを達成するためのより良い方法を提案できますか?