now intend to display a table on one page , the form displays the order record , using JSTL tag , as follows
<table >
<thead>
<tr>
<th>订单编号</th>
<th>桌号</th>
<th>下单时间</th>
<th>总价</th>
</tr>
</thead>
<tbody>
<c:forEach items="${orderlist}" var="tbl">
<tr>
<td>${tbl.id}</td>
<td>${tbl.tabletbl.id}</td>
<td>${tbl.orderTime}</td>
<td>
<!--
这里要怎么写啊怎么写,没有思路。。
这里对应的是订单的总价,应该将订单里面的商品set集合循环遍历,取出每一条商品的价格,
然后相加显示在这个单元格中
循环是这个样子写:(orderdetailtbls是商品的set集合)
<c:forEach items="${tbl.orderdetailtbls}" var="od_list">
然后在这里把${od_list.price}相加,可是相加的数据要放在哪里?
</c:forEach>
-->
</td>
.....
......
</table>
======================
roughly at that question , to ask how to write his words, the younger rookie , very grateful !
------ Solution ---------------------------------------- ----
<c:set var="totalPrice" value="${0}"></c:set>
<c:forEach items="${tbl.orderdetailtbls}" var="od_list">
<c:set var="totalPrice" value="${totalPrice+ od_list.price}"/>
</c:forEach>
${totalPrice}
------ For reference only ---------------------------- -----------
Thanks !
没有评论:
发表评论