我怎么能认识到这一点与JSP和JSTL?如何计算总求和的JSTL
int total = 0;
for (Article article : list) {
total += article.price;
}
我怎么能认识到这一点与JSP和JSTL?如何计算总求和的JSTL
int total = 0;
for (Article article : list) {
total += article.price;
}
使用<c:set>
初始化total变量,使用<c:forEach>
遍历列表并使用另一个<c:set>
的迭代值加总。
<c:set var="total" value="${0}"/>
<c:forEach var="article" items="${list}">
<c:set var="total" value="${total + article.price}" />
</c:forEach>
另请参阅Iterate over elements of List and Map using JSTL <c:forEach> tag。
上面就像。使用来设置总数。使用进行循环。 –
rickz
2014-12-03 14:48:32