日期:2014-05-20  浏览次数:20804 次

求助:JSTL中的<c:foreach>遍历怎么才能算出总销售-本金=总利润

<c:forEach items = "${shopList}" var = "shop">
    <tr>
        <td>${shop.shopID}元</td>
<td>${shop.shopName}元</td>
<td>${shop.costPrice}元</td>
<td>${shop.flatPrice}元</td>
<td>${shop.flatPrice - shop.costPrice}元</td>
    </tr>
</c:forEach>
    <tr>
<td colspan="4" align="center">总利润</td>
<td>
???????---------------
</td>
    </tr>


图:

------解决方案--------------------

<c:set var="sum" value="0"/>
<c:forEach items = "${shopList}" var = "shop">
    <tr>
        <td>${shop.shopID}元</td>
    <td>${shop.shopName}元</td>
    <td>${shop.costPrice}元</td>
    <td>${shop.flatPrice}元</td>
    <td>${shop.flatPrice - shop.costPrice}元<c:set var="sum" value="${sum+shop.flatPrice - shop.costPrice}"/></td>
    </tr>
</c:forEach>
    <tr>
    <td colspan="4" align="center">总利润</td>
    <td>
    ${sum}
    </td>
    </tr>