c:forEach usage

<c:foreach> is similar to for and foreach loops The following are the usages I have seen so far:
1. Loop through and output all elements.
<c:foreach items="${list}" var="li">
${li}
</c:foreach>
Note: items are used to receive collection objects, var defines objects to receive each element traversed from the collection . At the same time it will automatically transform.
2. Loop through and output an element of a range class.
<c:foreach items="${lis}" var = "li " begin="2" end ="12">
${li}
</c:foreach>
Note: begin defines the starting position of the traversal, and end defines the traversal end position. Begin and end quotes must be written.
3. Loop through, output elements other than a certain element or output a specified element.
<c:foreach items="${list}" var ="li" varStatus="status">
<c:if text="${status.count==1}>
${"don't need the first element"}
</c:if>
${li}
</c:foreach>
Note: varStatus indicates the status of the current collection (in fact, I don't know if it is, I only know how to use it in this way, and someone who knows will give pointers), and count is a calculator for looping.
4. Loop through and output the first or last element.
<c:foreach items="${list}" var ="li" varStatus="status">
<c:if text="${status.first}">I am the first element</c:if>
<c:if text="${status.last}">I am the last element</c:if>
</c:foreach>
Note: first means if it is an element, return true, otherwise return false
           last Indicates that if it is the last element, it will return true, otherwise it will return false.
5. Loop through and output according to the specified step size.
<c:foreach items="list" var ="li" step="2">
${li}
</c:foreach>

Guess you like

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