在jsp中<c:foreach>做2个list循环,这个问题该怎样修改?
在原来的时候我是这样写的:但是如果group下有100组数据,我就要去取1w次...,难以想象要是数据很多的话,那样的性能问题太严重了
ExtraFunction extra = null;
List<ExtraFunction> extraList = new ArrayList<ExtraFunction>();
for(Group group : groupList){
extra = extraService.getExtraFunctionByGroupId(group.getGroupId());
extraList.add(extra);
}
request.setAttribute("extraList", extraList);
...
<c:forEach var="group" items="${groupList}" varStatus="st">
<c:forEach var="extra" items="${extraList}" varStatus="st1">
<c:if test="${st.index==st1.index}">
...//只有当两个list的下标都一样的时候,再去循环。
</c:if>
</c:forEach>
</c:forEach>
ExtraFunction extra = null;
List<Object[]> groupDetails = new ArrayList<Object[]>();
for(Group group : groupList){
Object[] unitArray = new Object[2];
unitArray[0] = group;
unitArray[1] = extraService.getExtraFunctionByGroupId(group.getGroupId());
groupDetails.add(unitArray);
}
request.setAttribute("groupDetails", groupDetails);
...
<c:forEach var="group" items="${groupDetails}" varStatus="st">
<c:if test="${group[1].isPublic == 1 && group[0].status == 1}"><c:if>
...
<c:forEach var="group" items="${groupList}" varStatus="st">
...
<a href="<c:if test="${extraMap[st.index].isPublic == 1 && group.status == 1}">
...