当前位置: 代码迷 >> 综合 >> jsp通过jstl的forEach循环遍历list集合数据到table表格
  详细解决方案

jsp通过jstl的forEach循环遍历list集合数据到table表格

热度:62   发布时间:2024-01-29 13:03:23.0

直接换掉要遍历的集合数据可使用

<table class="userList"><!-- ${ro.urList }:要遍历的list集合 --><!-- 从第一个元素开始遍历 --><c:set var="temp" value="0"></c:set><!-- 3个td一行 --><c:set var="brCount" value="3"></c:set><c:forEach begin="0" end="${ro.urList.size()/brCount }"><tr><c:set var="num" value="0"></c:set><c:forEach var="ur" begin="${temp }" end="${temp+brCount-1 }"  items="${ro.urList }"><td>${ur.buName }</td><c:set var="num" value="${num+1 }"></c:set></c:forEach><!-- 如果最后一行数据没填满,则补充空td --><c:if test="${num<brCount }"><c:forEach begin="1" end="${brCount-num }"><td></td></c:forEach></c:if><c:set var="temp" value="${temp+brCount }"></c:set></tr></c:forEach>
</table>

 

  相关解决方案