评估列表是否为空JSTL


121

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

<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是否为空?

Answers:


245

empty运算符

所述empty操作者是一个前缀,可以被用来确定一个值是否为空值或空白操作。

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

2
尽管有文献证明,在v2.0之前的版本中,空操作符不能很好地配合JSTL中Collections的Set实现
casey 2010年

67

还有功能标签,更加灵活:

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

这里的标签文档。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.