2016-07-22 71 views
0

我的代碼是這樣的:評估2個條件表達式在第一個:如果第或:除非

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> 
     <h1 class="page-header" th:utext="#{dashboard}">Dashboard</h1> 
    </div> 

    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" th:if="${lista}"> 
     <h1 class="page-header" th:text="#{__${name}__}"></h1> 
    </div> 

    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" th:if="${command}"> 
     <h1 class="page-header"><th:block th:utext="#{__${action}__}"/> <th:block th:utext="#{__${name}__}"/></h1> 
    </div> 

如果lista不爲空的第二<div>塊被顯示。當command不爲空時顯示第三個。當listacommand都爲空時,應顯示第一個。類似的東西:

${lista} && ${command} 

但這個表達式會導致錯誤。任何人都知道如何做到這一點?

UPDATE

我嘗試:${lista && command}${lista and command}但不解決我的問題(仍然happenning錯誤)。

+0

的可能的複製[如何在一個個多重條件:如果使用標籤thymeleaf(http://stackoverflow.com/questions/16018577/how-到具有-多個輸入條件-AN-THIF標籤的使用-thymeleaf) – Andrew

回答

1

我想@Andrew引用了正確的鏈接。 如果您需要檢查lista爲空並且command爲null,請檢查它。 我不確定,但這種語法不正確我猜 - th:if="${lista}"
改爲使用th:if="${lista != null}"

因此,對於檢查兩個條件:

th:if="${lista == null and command == null}" 
相關問題