簡體   English   中英

jstl可以檢查屬性是否已添加到模型嗎?

[英]Can jstl check if attribute has been added to the model?

是否可以檢查屬性是否已添加到模型?

//in the controller teh variable is not always added
//
model.addAttribute("variable", myVariable);

在jsp中是這樣的

<c:choose>
    <c:when test="${variable is present}">
        Not present
    </c:when>
    <c:otherwise>
        Present
    </c:otherwise>
</c:choose>

謝謝

JSTL / EL無法檢查是否已將屬性添加到模型。 為此,您需要自己實現一個觀察者/可觀察者。

但是,EL可以檢查bean屬性或映射值是否不為null或為空。

<c:when test="${not empty bean.property}">

<c:when test="${not empty map.key}">

也可以看看:

您可以檢查屬性是否為空

<c:if test="${not empty post}">
   <h3>${post.title}</h3>   
</c:if>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM