Another solution is just using not
to get the opposite negation:
<h2 th:if="${potentially_complex_expression}">Hello!</h2>
<span class="xxx" th:if="${not potentially_complex_expression}">Something else</span>
As explained in the documentation, it's the same thing as using th:unless
. As other answers have explained:
Also,
th:if
has an inverse attribute,th:unless
, which we could have used in the previous example instead of using a not inside the OGNL expression
Using not
also works, but IMHO it is more readable to use th:unless
instead of negating the condition with not
.