您的位置:首页 > 其它

关于<c:forEach>取得集合数量的问题

2015-04-16 16:26 302 查看
网上看到这个问题其中使用了:

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

用其length属性可以获得集合数量:${fn:length(list)} (fn后面是冒号)其中的list就是<c:forEach>标签中items属性的值

试了一下:直接用集合的size方法也行。

<c:forEach items="${roleList}" var="role" varStatus="status">

<c:if test="${status.index % 3 == 0 }">

<tr>

</c:if>

<td align="left">[<a href='editRole.do?RoleID=${role.roleID }'>${role.roleName }</a>]<br /></td>

<c:if test="${(status.index+1) % 3 == 0 }">

</tr>

</c:if>

<c:if test="${status.count == roleList.size() }">

</tr>

</c:if>

</c:forEach>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: