jstl foreach省略最后一条记录中的元素 [英] jstl foreach omit an element in last record

查看:46
本文介绍了jstl foreach省略最后一条记录中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用此jstl来表示json字符串,我如何使该段不在最后一个记录的末尾添加逗号?最后注意逗号

trying to use this jstl to formulate a json string, how can i make the segment not to put a comma in the end of the last record? note the comma in the end

<c:forEach items="${fileList}" var="current">
    { id:1001,data:["<c:out value="${current.fileName}" />" , "<c:out value="${current.path}" />" , "<c:out value="${current.size}" />" , "<c:out value="${current.type}" />"] },
</c:forEach>

推荐答案

只需使用

您也可以在EL中使用条件运算符代替<c:if>:

You can also use the conditional operator in EL instead of <c:if>:

    ${!loop.last ? ',' : ''}

这篇关于jstl foreach省略最后一条记录中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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