필요성 : c태그 forEach속성의 리스트를 순환할때, 인덱스별 if속성을 멕이고싶을때 사용함.
forEach에 varStatus를 이용하면 iteration 번호 알 수 있음.
(예시)
<c:forEach var="m" items="${monthCashOutLine}" varStatus="status">
<c:choose>
<%-- day의 값이 0이면 BeginBlank. 빈 셀 넣기 --%>
<c:when test="${m.day == 0}">
<td></td>
</c:when>
<c:otherwise>
<td>
<div>
<a href="${pageContext.request.contextPath}/member/cashListByDate?year=${year}&month=${month+1}&date=${m.day}">
${m.day}
</a>
</div>
<hr>
<%-- 날짜별 수입, 지출 개요 --%>
<div>수입 : ${m.income}</div>
<div>지출 : ${m.outcome}</div>
<hr>
<div>합계 : ${m.total}</div>
</td>
</c:otherwise>
</c:choose>
<%-- 토요일(6))까지 입력한뒤 줄을 닫고, 새로운 행 시작하기 --%>
<c:if test="${status.index % 7 == 6}">
</tr><tr> <!-- 새로운 행 시작 -->
</c:if>
</c:forEach>
<varStatus 가 쓰인 곳>
<c:forEach var="m" items="${monthCashOutLine}" varStatus="status"> |
<c:if test="${status.index % 7 == 6}"> </tr><tr> <!-- 새로운 행 시작 --> </c:if> |
status( varStatus ).index 로 for문의 현재 인덱스를 알 수 있다.
<varStatus의 상태변수>
status.index | 0부터 시작, 현재 for문이 순환한 횟수를 구해준다 |
status.count | 1부터 시작, 상동 |
status.end | for문의 끝 번호 |
'SPRING' 카테고리의 다른 글
[Service & MySQL 에러] SQLIntegrityConstraintViolationException (0) | 2024.11.13 |
---|---|
[java 에러] row cannot be resolved to a variable (0) | 2024.11.13 |
{fn:substring} HTML 에서 글자열 자르기 (0) | 2024.11.12 |
[2024-11-07]쿼리파라미터 전달, DB 기본값 Null (0) | 2024.11.08 |
디버깅 및 인터셉트 (0) | 2024.10.31 |