使用JSTL检查集合大小 [英] Check a collection size with JSTL

查看:92
本文介绍了使用JSTL检查集合大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JSTL检查集合的大小?

How can I check the size of a collection with JSTL?

类似于:

<c:if test="${companies.size() > 0}">

</c:if>


推荐答案

来自: http://java.sun.com/products/jsp/jstl/1.1/ docs / tlddocs / fn / tld-summary.html


length(java.lang.Object) - 返回集合中的项目数或字符串中的字符数。

length( java.lang.Object) - Returns the number of items in a collection, or the number of characters in a string.

将其置于顶部允许fn命名空间的页面:

put this at the top of the page to allow the fn namespace:

 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

并在jsp页面中使用如下:

and use like this in your jsp page:

<p>The length of the companies collection is : ${fn:length(companies)}</p>

所以要测试一个集合的长度:

So to test with length of a collection:

<c:if test="${fn:length(companies) gt 0}">
   <p>It is greater than 0</p>
</c:if>

注意使用 gt 代替< jsp / jsf标记内不允许使用code>> >

这篇关于使用JSTL检查集合大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆