jsp技术之“如何在jsp中判断属性为空”

一、判断对象列表为空不显示某段代码

<%-- 展开子属性 --%>
<c:if test="${not empty product.variations}">
    <div style="position: absolute; bottom: 0; margin-bottom: 5px;">
        <button type="button" class="btn default" onclick="expandVariations(this, '${product.productSku}')">
            <i class="icon-minus"></i>
        </button>
    </div>
</c:if>

 

二、判断字段是否为true,来决定显不显示代码

<c:if test="${product.productExtend.isAutoPublish}">
    <div>
        <span class="label custom label-success">自动刊登</span>
    </div>
</c:if>

 

 

三、判断如果是执行某些代码,否则显示某些代码

<c:choose>
    <%-- 仓库专用标签 --%>
    <c:when test="${product.feature == '重量差异' }">
        <c:if test="${app:auth('11104200') }">
            <span id="product-label-${product.productId }-${feature }"><span class="label label-danger label-sm">${feature }</span></span><br>
        </c:if>
    </c:when>
    <c:when test="${feature == '7天+缺货未发' && isExistAmazonPlatform && department.departmentType == 1}"></c:when>
    <c:otherwise>
        <span id="product-label-${product.productId }-${feature }"><span class="label label-danger label-sm">${feature }</span></span><br>
    </c:otherwise>
</c:choose>

 

posted @ 2023-01-10 16:56  骚哥  阅读(773)  评论(0编辑  收藏  举报