jstl 对list集合进行求和

1.情景展示

<table style="order-collapse: collapse;" cellspacing="0" cellpadding="1" border="0" width="99%">
    <tbody>
        <tr class="TableHeader" align="center">
            <td class="TableHeaderCell" nowrap="nowrap">日期</td>
            <td class="TableHeaderCell" nowrap="nowrap">线上正式卡</td>
            <td class="TableHeaderCell" nowrap="nowrap">线上临时卡</td>
            <td class="TableHeaderCell" nowrap="nowrap">线下正式卡</td>
            <td class="TableHeaderCell" nowrap="nowrap">线下临时卡</td>
        </tr>
        <c:forEach var="card" items="${model.data}">
        <tr class="TableRow" align="center">
            <td nowrap="nowrap" class="TableCell" align="left">${card.REGTIME}</td>
            <td nowrap="nowrap" class="TableCell" align="left">${card.ONLINE_FORMAL}</td>
            <td nowrap="nowrap" class="TableCell" align="left">${card.ONLINE_INFORMAL}</td>
            <td nowrap="nowrap" class="TableCell" align="left">${card.OFFLINE_FORMAL}</td>
            <td nowrap="nowrap" class="TableCell" align="left">${card.OFFLINE_INFORMAL}</td>
        </tr>
        </c:forEach>
    </tbody>
</table>  

jstl 对list集合进行求和

  如上图所示,在使用c:foreach标签迭代完毕后,需要加一行合计,对每列数据进行求和,如何实现?   

2.思路分析

  foreach标签起到Java里for循环的作用;

  set标签可以用于声明变量或者变量赋值;

  EL表达式支持各种数值运算和字符串函数。   

3.解决方案

<table style="order-collapse: collapse;" cellspacing="0" cellpadding="1" border="0" width="99%">
    <tbody>
        <tr class="TableHeader" align="center">
            <td class="TableHeaderCell" nowrap="nowrap">日期</td>
            <td class="TableHeaderCell" nowrap="nowrap">线上正式卡</td>
            <td class="TableHeaderCell" nowrap="nowrap">线上临时卡</td>
            <td class="TableHeaderCell" nowrap="nowrap">线下正式卡</td>
            <td class="TableHeaderCell" nowrap="nowrap">线下临时卡</td>
        </tr>
        <c:forEach var="card" items="${model.data}">
        <tr class="TableRow" align="center">
            <td nowrap="nowrap" class="TableCell" align="left">${card.REGTIME}</td>
            <td nowrap="nowrap" class="TableCell" align="left">
                ${card.ONLINE_FORMAL}
                <c:set var="SUM_ONLINE_FORMAL" value="${SUM_ONLINE_FORMAL + card.ONLINE_FORMAL}"/>
            </td>
            <td nowrap="nowrap" class="TableCell" align="left">
                ${card.ONLINE_INFORMAL}
                <c:set var="SUM_ONLINE_INFORMAL" value="${SUM_ONLINE_INFORMAL + card.ONLINE_INFORMAL}"/>
            </td>
            <td nowrap="nowrap" class="TableCell" align="left">
                ${card.OFFLINE_FORMAL}
                <c:set var="SUM_OFFLINE_FORMAL" value="${SUM_OFFLINE_FORMAL + card.OFFLINE_FORMAL}"/>
            </td>
            <td nowrap="nowrap" class="TableCell" align="left">
                ${card.OFFLINE_INFORMAL}
                <c:set var="SUM_OFFLINE_INFORMAL" value="${SUM_OFFLINE_INFORMAL + card.OFFLINE_INFORMAL}"/>
            </td>
        </tr>
        </c:forEach>
        <tr class="TableRow" align="center">
            <td nowrap="nowrap" class="TableCell" align="left">合计</td>
            <td nowrap="nowrap" class="TableCell" align="left">${SUM_ONLINE_FORMAL}</td>
            <td nowrap="nowrap" class="TableCell" align="left">${SUM_ONLINE_INFORMAL}</td>
            <td nowrap="nowrap" class="TableCell" align="left">${SUM_OFFLINE_FORMAL}</td>
            <td nowrap="nowrap" class="TableCell" align="left">${SUM_OFFLINE_INFORMAL}</td>
        </tr>
    </tbody>
</table>

  

写在最后

  哪位大佬如若发现文章存在纰漏之处或需要补充更多内容,欢迎留言!!!

 相关推荐:

 

jstl 对list集合进行求和

上一篇:Idea-每次修改JS文件都需要重启Idea才能生效解决方法


下一篇:使用原生js实现一个列表数据展示页面不同的项目状态使整行显示不同颜色。