计算jstl中每个列的总计

编程入门 行业动态 更新时间:2024-10-27 18:32:17
本文介绍了计算jstl中每个列的总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的报告

01 jan 02 jan 03 jan ... total user1 3 5 10 18 user2 5 6 9 20 . . . total ? ? ? 38

我可以使用我的JSTL代码来计算每一行的总计。我找不到用'?'来计算结束标记的列总数的方法。

I am able to calulate each row total at end using my JSTL code. I don't find the way to calculate columns total at end mark with '?'.

对于行总数,我使用像

<c:forEach var="colNames" items="${listOfRecords}"> <tr> <td>${colNames.key}</td> <c:set var="htotal" value="0" /> <c:forEach var="noOfTasks" items="${colNames.value}" varStatus="status"> <td>${noOfTasks.value}</td> <c:set var="htotal" value="${htotal+noOfTasks.value}" /> </c:forEach> <td class="foo">${htotal}</td> </tr> </c:foreach>

这里 $ {listOfRecords} c $ c> HashMap< String,HashMap< String,Integer>> 。

Here ${listOfRecords} is HashMap<String, HashMap<String, Integer>>.

如何实现?

推荐答案

这是我能够想出的:

<jsp:useBean id="column_totals" class="java.util.LinkedHashMap" scope="page"/> <c:forEach var="row" items="${listOfRecords}"> <tr> <td>${row.key}</td> <c:set var="row_total" value="0"/> <c:forEach var="column" items="${row.value}"> <td>${column.value}</td> <c:if test="${empty column_totals[column.key]}"> <c:set target="${column_totals}" property="${column.key}" value="0"/> </c:if> <c:set target="${column_totals}" property="${column.key}" value="${column_totals[column.key] + column.value}"/> <c:set var="row_total" value="${row_total + column.value}" /> </c:forEach> <td class="foo">${row_total}</td> </tr> </c:foreach> <tr> <td>total</td> <c:forEach var="column_total" items="${column_totals}"> <td>${column_total.value}</td> </c:forEach> </tr>

不能改变一些名字,因为我不明白你的对不起。

Had to change some names cause I couldn't understand with yours sorry.

我认为它应该工作。

更多推荐

计算jstl中每个列的总计

本文发布于:2023-11-22 04:17:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jstl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!