2013年9月23日星期一

JSTL assignment problem

I have two tables, an order form, a merchandise table , the two are many relationship .

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 , the sum of the value placed where ? Or how to write his words, the younger rookie , very grateful !
------ Solution ---------------------------------------- ----
outside the loop definition:

<c:set var="a" value="0"></c:set>


loop :

<c:set var="a" value="${a+od_list.price}"></c:set>


final output
$ {a}

Try
------ For reference only -------------------------------- -------
thanks, upstairs you can !

没有评论:

发表评论