jstl c:foreach 倒序巢狀輸出
阿新 • • 發佈:2019-01-30
使用c標籤,fn標籤;
jsp程式碼如下:
<!DOCTYPE html> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <meta name="format-detection" content="telephone=no"> <meta charset="UTF-8"> </head> <style> #content { margin-left: 0px; margin-right: 0px; } body { background-color: #ffffff; } div{ border-radius: 0!important; } .register-item { line-height: 220%; color: #999; font-size: 12px; border-top: 1px solid #dedfde; border-left: 1px solid #dedfde; border-right: 1px solid #dedfde; margin-top: -1px; } .register-item h3 { font-weight: 600; text-align: left; float: left; width: 100px; font-size: 12px; margin-top: 10px!important; margin-left: 20px!important; font-family: "Open Sans",sans-serif; margin-bottom: 10px; line-height: 1.1; color: inherit; } .register-item dl { margin-left: 120px; border-left: 1px solid #dedfde; } dd, dt { line-height: 1.42857; } dl, dt, dd { margin: 0; padding: 0; list-style: none; } dt { font-weight: 700; } .register-item dt:first-of-type { border-top: none; } .register-item dt { width: 150px; float: left; text-align: left; border-top: 1px solid #dedfde; padding: 10px; } .register-item dd:first-of-type { border-top: none; } .register-item dd { margin-left: 150px; border-left: 1px solid #dedfde; border-top: 1px solid #dedfde; padding: 10px; } .register-item dd span { min-height: 17px; display: block; } </style> <body> <div id="content"> <c:forEach var="groupType" items="${groupTypes}" varStatus="status"> <c:set var="groupTypesize" value="${fn:length(groupType.groupList)}"/> <c:forEach items="${groupType.groupList}" varStatus="status"> <c:set var="group" value="${groupType.groupList[groupTypesize- status.index - 1]}"/> <div class="register-item"> <h3>${group.groupDisplayName}</h3> <dl> <c:set var="attributesize" value="${fn:length(group.attributes)}"/> <c:forEach items="${group.attributes}" varStatus="status"> <c:set var="attribute" value="${group.attributes[attributesize- status.index - 1]}"/> <dt class=" select">${attribute.attributeDisplayName}</dt> <dd> <span class="leave2span attributeTag">${attribute.attributeDefaultValue}</span> </dd> </c:forEach> </dl> </div> </c:forEach> </c:forEach> </div> </body> </html>