2017-06-29 46 views
-1

我有这片我Thymeleaf HTML网页代码,我想知道是否有可能把,如果别人在同一语句Thymeleaf HTML如果别人在同一行

<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> 

回答

2

试试像这样:

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>