2017-06-29 47 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>