【问题标题】:Evaluate if list is empty JSTL评估列表是否为空 JSTL
【发布时间】:2021-11-03 16:52:17
【问题描述】:

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

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

【问题讨论】:

    标签: java jsp jstl


    【解决方案1】:

    empty 是一个运算符

    empty 操作符是一个 前缀 操作,可用于确定 值是 null 还是空。

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

    【讨论】:

    • 尽管据记载,空运算符在 v2.0 之前的 JSTL 中的集合实现中不能很好地发挥作用
    【解决方案2】:

    还有函数标签,更灵活一点:

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

    还有here's标签文档。

    【讨论】:

      猜你喜欢
      • 2011-02-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2011-09-05
      • 2016-09-20
      • 2015-01-18
      • 1970-01-01
      相关资源
      最近更新 更多