解决问题:怎样在页面获取数组和List集合的长度
我们在前端遍历后台数据的时候,经常是从后台传过来一个数组或List集合,在前端页面就可以使用JSTL的<c:For each>标签遍历数据了。但是有时候我们需要更加深入控制遍历的逻辑,这时候数组或List的长度就是一个必不可少的信息了。
首先,在jsp页面上,我们不能够使用${testList.length}和${testList.size}来获取List集合的长度,这是EL表达式的API决定的。
那么,在jsp页面上怎样获取数组或List集合的长度呢?
①导入JSTL的函数标签库
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
②使用fn:length函数
${fn:length(testList)}
——例 如:
<c:if test="${varStatus.count==fn:length(allInform)-1}"> <a class="blue" >下移<i class="ace-icon glyphicon glyphicon-arrow-down bigger-130"></i> </a> </c:if> <c:if test="${varStatus.count!=fn:length(allInform)-1}"> <a class="blue" href="#" onclick="javascript:location.href='${pageContext.request.contextPath}/manager/toInformDown/${inform.get(‘inform_order’)}'"> 下移<i class="ace-icon glyphicon glyphicon-arrow-down bigger-130"></i> </a> </c:if>
———————————————————————————————————————————————————————————————————
The end @ 万有引力+
-
-
-
-
-