问题

我一直在试图评估这个数组列表是否为空,但这些数据列表都没有编译:

<c:if test="${myObject.featuresList.size == 0 }">                   
<c:if test="${myObject.featuresList.length == 0 }">                 
<c:if test="${myObject.featuresList.size() == 0 }">                 
<c:if test="${myObject.featuresList.length() == 0 }">                   
<c:if test="${myObject.featuresList.empty}">                    
<c:if test="${myObject.featuresList.empty()}">                  
<c:if test="${myObject.featuresList.isEmpty}">

如何评估ArrayList是否为空?


#1 热门回答(226 赞)

empty是运营商。

<c:if test="${empty myObject.featuresList}">

#2 热门回答(63 赞)

还有功能标签,更灵活一点:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:if test="${fn:length(list) > 0}">

Andhere's标签文档。


原文链接