EL expression traverses the collection to get the subscript

As the title, HTML pages often need to loop through a collection, and get the subscript of the collection element for judgment, or pass the subscript to the background as a parameter

Then we need to use the varStatus of the EL expression

代码一:
<c:forEach var="news" items="${newlist}" varStatus="index">
<p><a class="newInfo" href="${pageContext.request.contextPath}/static/toNewView/${index.index}/${news.nId}">${news.title}...</a></p>
</c:forEach>

代码二:
<c:forEach var="card" items="${browseList}" varStatus="indexo">
<ul>
<li class="shopping_commend_list_1">·<a href="${pageContext.request.contextPath}/static/toCardView/${card.cId}/${card.gid}" class="blue">${card.cName}</a></li>
<li class="shopping_commend_list_2">¥${card.iniPrice}</li>
<li class="shopping_commend_list_3">¥${card.price}</li>
<li class="shopping_commend_list_4"><a href="#" class="shopping_yellow">购买</a></li>
<li class="shopping_commend_list_5" style="display: none">${card.titleImg}</li>
<li class="shopping_commend_list_6" style="display: none">${card.gName}</li>
<li class="shopping_commend_list_7" style="display: none">${card.cName}</li>
<li class="shopping_commend_list_8" style="display: none">${card.cId}</li>
<li class="shopping_commend_list_9" style="display: none">${card.gid}</li>
</ul>
<c:if test="${indexo.count/1==5}">
</div>
<div class="shopping_commend_sort_mid"></div>
<div class="shopping_commend_sort_left">
</c:if>
<c:if test="${indexo.last}">
</div>
</div>
</c:if> To sum up: Use varStatus.index and varStatus.count to get the corresponding subscript value.
</c:forEach>




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324976964&siteId=291194637