JSTL for each分隔符 [英] JSTL forEach separator

查看:132
本文介绍了JSTL for each分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任务是在每次迭代后输出分隔符(如逗号),除了最后一个(或者除第一个之外)。是否有foreach的ELSE标记?

解决方案使用 varStatus 属性,它引用了一个 LoopTagStatus类型的对象

 < c:forEach var =fooitems =$ {foos}varStatus =loopStatus> 
< c:out value =$ {foo}/>
< c:if test =$ {!loopStatus.last}> | < / C:如果>
< / c:forEach>


Is there a built in feature in JSTL to output separators while doing foreach?

The task is to output separators (like commas) after each iteration except the last one (or before each except the first). Is there any ELSE tag for foreach?

解决方案

Use the varStatus attribute, which references an object of type LoopTagStatus:

<c:forEach var="foo" items="${foos}" varStatus="loopStatus">
    <c:out value="${foo}"/>
    <c:if test="${!loopStatus.last}"> | </c:if>
</c:forEach>

这篇关于JSTL for each分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆