网上图书商城项目学习笔记-020订单详情

一、流程分析

网上图书商城项目学习笔记-020订单详情_第1张图片

二、代码

1.view层

(1)list.jsp

 1 <div class="divMain">
 2     <div class="divTitle">
 3         <span style="margin-left: 150px;margin-right: 280px;">商品信息</span>
 4         <span style="margin-left: 40px;margin-right: 38px;">金额</span>
 5         <span style="margin-left: 50px;margin-right: 40px;">订单状态</span>
 6         <span style="margin-left: 50px;margin-right: 50px;">操作</span>
 7     </div>
 8     <br/>
 9     <table align="center" border="0" width="100%" cellpadding="0" cellspacing="0">
10 
11 
12 <c:forEach items="${pb.beanList }" var="o">
13 
14         <tr class="tt">
15             <td width="320px">订单号:<a  href="<c:url value='/OrderServlet?method=load&oid=${o.oid }'/>">${o.oid }</a></td>
16             <td width="200px">下单时间:${o.orderTime }</td>
17             <td>&nbsp;</td>
18             <td>&nbsp;</td>
19             <td>&nbsp;</td>
20             <td>&nbsp;</td>
21         </tr>
22         <tr style="padding-top: 10px; padding-bottom: 10px;">
23             <td colspan="2">
24 
25 
26     <c:forEach items="${o.orderItems }" var="oi">
27     <a class="link2" href="<c:url value='/BookServlet?method=load&bid=${oi.book.bid }'/>">
28         <img border="0" width="70" src="<c:url value='/${oi.book.image_b }'/>"/>
29     </a>
30     </c:forEach>
31 
32 
33             </td>
34             <td width="115px">
35                 <span class="price_t">&yen;${o.total }</span>
36             </td>
37             <td width="142px">
38 <c:choose>
39     <c:when test="${o.status eq 1 }">(等待付款)</c:when>
40     <c:when test="${o.status eq 2 }">(准备发货)</c:when>
41     <c:when test="${o.status eq 3 }">(等待确认)</c:when>
42     <c:when test="${o.status eq 4 }">(交易成功)</c:when>
43     <c:when test="${o.status eq 5 }">(已取消)</c:when>
44 </c:choose>
45             </td>
46             <td>
47             <a href="<c:url value='/OrderServlet?method=load&oid=${o.oid }'/>">查看</a><br/>
48 <c:if test="${o.status eq 1 }">
49                 <a href="<c:url value='/OrderServlet?method=load&oid=${o.oid }'/>">支付</a><br/>
50                 <a href="<c:url value='/OrderServlet?method=load&btn=cancel&oid=${o.oid }'/>">取消</a><br/>                        
51 </c:if>
52 <c:if test="${o.status eq 3 }">
53                 <a href="<c:url value='/OrderServlet?method=load&btn=confirm&oid=${o.oid }'/>">确认收货</a><br/>
54 </c:if>
55             </td>
56         </tr>
57 </c:forEach>
58 
59     </table>
60     <br/>
61     <%@include file="/jsps/pager/pager.jsp" %>
62 </div>

 

(2)desc.jsp

 1 <body>
 2     <div class="divOrder">
 3         <span>订单号:${order.oid }
 4 <c:choose>
 5     <c:when test="${order.status eq 1}">(等待付款)</c:when>
 6     <c:when test="${order.status eq 2}">(准备发货)</c:when>
 7     <c:when test="${order.status eq 3}">(等待确认)</c:when>
 8     <c:when test="${order.status eq 4}">(交易成功)</c:when>
 9     <c:when test="${order.status eq 5}">(已取消)</c:when>
10 </c:choose>
11            下单时间:${order.orderTime }</span>
12     </div>
13     <div class="divContent">
14         <div class="div2">
15             <dl>
16                 <dt>收货人信息</dt>
17                 <dd>${order.address }</dd>
18             </dl>
19         </div>
20         <div class="div2">
21             <dl>
22                 <dt>商品清单</dt>
23                 <dd>
24                     <table cellpadding="0" cellspacing="0">
25                         <tr>
26                             <th class="tt">商品名称</th>
27                             <th class="tt" align="left">单价</th>
28                             <th class="tt" align="left">数量</th>
29                             <th class="tt" align="left">小计</th>
30                         </tr>
31 
32 
33 <c:forEach items="${order.orderItems }" var="oi">
34                         <tr style="padding-top: 20px; padding-bottom: 20px;">
35                             <td class="td" width="400px">
36                                 <div class="bookname">
37                                   <img align="middle" width="70" src="<c:url value='/${oi.book.image_b }'/>"/>
38                                   <a href="<c:url value='/BookServlet?method=load&bid=${oi.book.bid }'/>">${oi.book.bname }</a>
39                                 </div>
40                             </td>
41                             <td class="td" >
42                                 <span>&yen;${oi.book.currPrice }</span>
43                             </td>
44                             <td class="td">
45                                 <span>${oi.quantity }</span>
46                             </td>
47                             <td class="td">
48                                 <span>&yen;${oi.subtotal }</span>
49                             </td>            
50                         </tr>
51 </c:forEach>
52 
53                     </table>
54                 </dd>
55             </dl>
56         </div>
57         <div style="margin: 10px 10px 10px 550px;">
58             <span style="font-weight: 900; font-size: 15px;">合计金额:</span>
59             <span class="price_t">&yen;${order.total }</span><br/>
60 <c:if test="${order.status eq 1 }">
61     <a href="<c:url value='/jsps/order/pay.jsp'/>" class="pay"></a><br/>
62 </c:if>    
63 <c:if test="${order.status eq 1 and btn eq 'cancel' }">
64     <a id="cancel" href="javascript:alert('订单已取消!');">取消订单</a><br/>
65 </c:if>
66 <c:if test="${order.status eq 3 and btn eq 'confirm' }">
67     <a id="confirm" href="javascript:alert('交易成功!');">确认收货</a><br/>
68 </c:if>
69         </div>
70     </div>
71 </body>

 

2.servlet层

(1)OrderServlet.java 

 1     /**
 2      * 加载订单
 3      * @param req
 4      * @param resp
 5      * @return
 6      * @throws ServletException
 7      * @throws IOException
 8      */
 9     public String load(HttpServletRequest req, HttpServletResponse resp)
10             throws ServletException, IOException {
11         String id = req.getParameter("oid");
12         String btn = req.getParameter("btn");
13         Order order = service.load(id);
14         req.setAttribute("order", order);
15         req.setAttribute("btn", btn);
16         return "f:/jsps/order/desc.jsp";
17     }

 

3.service层

(1)OrderSerivce.java 

 1     /**
 2      * 根据id加载订单
 3      * @param id
 4      * @return
 5      */
 6     public Order load(String id) {
 7         try {
 8             return dao.findById(id);
 9         } catch (SQLException e) {
10             throw new RuntimeException(e);
11         }
12     }

 

4.dao层

(1)OrderDao.java

 1     /**
 2      * 根据id查找
 3      * @param id
 4      * @return
 5      * @throws SQLException
 6      */
 7     public Order findById(String id) throws SQLException {
 8         String sql = "select * from t_order where oid=?";
 9         Order order = qr.query(sql, new BeanHandler<Order>(Order.class), id);
10         loadOrderItem(order);
11         return order;
12     }
13 
14     /**
15      * 根据id查找
16      * @param id
17      * @return
18      * @throws SQLException
19      */
20     public Order findById(String id) throws SQLException {
21         String sql = "select * from t_order where oid=?";
22         Order order = qr.query(sql, new BeanHandler<Order>(Order.class), id);
23         loadOrderItem(order);
24         return order;
25     }

 

你可能感兴趣的:(网上图书商城项目学习笔记-020订单详情)