forEach处理List每行显示固定的几个 博客分类: Page
程序员文章站
2024-03-23 23:33:10
...
我用C标签中的forEach取值,如何每行显示4个,多的在第二行显示!
<c:forEach var="s" list="${list}" varStates="vs">
<c:if test="${vs.count%4==0}"><br></c:if>
</c:forEach>
以下是个实际的使用列子:(注意如果最后一行不是4个,就需要补充空的td,例子有处理,但需要传参数)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="sxlist_tab" name="table" id="table"> <thead> <tr> <th width="4%">序号</th> <th width="28%">事项类别</th> <th width="28%">项目名称</th> <th width="12%">提醒时间</th> <th width="28%">提醒内容</th> </tr> </thead> <tbody> <c:choose> <c:when test="${!empty effReceiveInstanceList}"> <c:forEach items="${effReceiveInstanceList}" var="effBean" varStatus="status"> <tr> <td> ${effBean.indexnum }</td> <td title='${effBean.apply_item_name}'> <c:choose> <c:when test="${fn:length(effBean.apply_item_name) > 20}"> <c:out value="${fn:substring(effBean.apply_item_name, 0, 20)}..." /> </c:when> <c:otherwise> <c:out value="${effBean.apply_item_name}" /> </c:otherwise> </c:choose> </td> <td title='${effBean.projectname }'> <c:choose> <c:when test="${fn:length(effBean.projectname) > 20}"> <c:out value="${fn:substring(effBean.projectname, 0, 20)}..." /> </c:when> <c:otherwise> <c:out value="${effBean.projectname }" /> </c:otherwise> </c:choose> </td> <td> ${effBean.sentdate }</td> <td title='${effBean.news_content }'> <c:choose> <c:when test="${fn:length(effBean.news_content) > 20}"> <c:out value="${fn:substring(effBean.news_content, 0, 20)}..." /> </c:when> <c:otherwise> <c:out value="${effBean.news_content }" /> </c:otherwise> </c:choose> </td> </tr> </c:forEach> </c:when> </c:choose> </tbody> </table>