我的 Thymeleaf HTML 页面中有这段代码,我想知道是否可以将 if else 放在同一语句中
<div th:if="${book.htmlIconColor != null}" >
<i class="fa fa-exchange fa-2x" th:style="${'color:' + book.htmlIconColor + '; text-align: center;'}" aria-hidden="true"></i>
</div>
<div th:if="${book.htmlIconColor == null}" >
<i class="fa fa-exchange fa-2x" aria-hidden="true"></i>
</div>
最佳答案
尝试这样的事情:
condition ? first_expression : second_expression;
例如
<i class="fa fa-exchange fa-2x" aria-hidden="true" th:style="${book.htmlIconColor} ? 'color:' + ${book.htmlIconColor} + '; text-align: center;' : 'text-align: center;'"></i>
关于html - Thymeleaf HTML if else 在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44819904/