zoukankan      html  css  js  c++  java
  • 网上图书商城项目学习笔记-021取消订单确认收货

    一、流程分析

    二、代码

    1.view层

    (1)desc.jsp

    1 <c:if test="${order.status eq 1 }">
    2     <a href="<c:url value='/OrderServlet?method=prePay&oid=${order.oid }'/>" class="pay"></a><br/>
    3 </c:if>    
    4 <c:if test="${order.status eq 1 and btn eq 'cancel' }">
    5     <a id="cancel" href="<c:url value='/OrderServlet?method=cancel&oid=${order.oid }'/>">取消订单</a><br/>
    6 </c:if>
    7 <c:if test="${order.status eq 3 and btn eq 'confirm' }">
    8     <a id="confirm" href="<c:url value='/OrderServlet?method=confirm&oid=${order.oid }'/>">确认收货</a><br/>
    9 </c:if>

     

    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 confirm(HttpServletRequest req, HttpServletResponse resp)
    10             throws ServletException, IOException {
    11         String id = req.getParameter("oid");
    12         int status = service.findStatus(id);
    13         
    14         if(status != 3) {
    15             req.setAttribute("code", "error");
    16             req.setAttribute("msg", "态不对,不能确认收货!");
    17             return "f:/jsps/msg.jsp";
    18         }
    19         service.updateStatus(id, 4);
    20         req.setAttribute("code", "success");
    21         req.setAttribute("msg", "恭喜,交易成功!");
    22         return "f:/jsps/msg.jsp";    
    23     }
    24     
    25     /**
    26      * 取消收货
    27      * @param req
    28      * @param resp
    29      * @return
    30      * @throws ServletException
    31      * @throws IOException
    32      */
    33     public String cancel(HttpServletRequest req, HttpServletResponse resp)
    34             throws ServletException, IOException {
    35         String id = req.getParameter("oid");
    36         int status = service.findStatus(id);
    37         
    38         if(status != 1) {
    39             req.setAttribute("code", "error");
    40             req.setAttribute("msg", "状态不对,不能取消!");
    41             return "f:/jsps/msg.jsp";
    42         }
    43         service.updateStatus(id, 5);
    44         req.setAttribute("code", "success");
    45         req.setAttribute("msg", "您的订单已取消!");
    46         return "f:/jsps/msg.jsp";    
    47     }

    3.service层

    (1)OrderService.java  

     1     /**
     2      * 修改订单状态
     3      * @param id
     4      * @param status
     5      */
     6     public void updateStatus(String id, int status) {
     7         try {
     8             dao.updateStatus(id, status);
     9         } catch (SQLException e) {
    10             throw new RuntimeException(e);
    11         }
    12     }
    13 
    14     /**
    15      * 查找订单状态
    16      * @param id
    17      * @return
    18      */
    19     public int findStatus(String id) {
    20         try {
    21             return dao.findStatus(id);
    22         } catch (SQLException e) {
    23             throw new RuntimeException(e);
    24         }
    25     }

    4.dao层

    (1)OrderDao.java

     1     /**
     2      * 修改订单状态
     3      * @param id
     4      * @param status
     5      * @throws SQLException
     6      */
     7     public void updateStatus(String id, int status) throws SQLException {
     8         String sql = "update t_order set status=? where oid=?";
     9         qr.update(sql, status, id);
    10     }
    11     
    12     /**
    13      * 查找订单状态
    14      * @param id
    15      * @return
    16      * @throws SQLException
    17      */
    18     public int findStatus(String id) throws SQLException {
    19         String sql = "select status from t_order where oid=?";
    20         Number status = (Number) qr.query(sql, new ScalarHandler(), id);
    21         return status.intValue();
    22     }
  • 相关阅读:
    导出excel
    JS一些记录
    Concat
    (二)《SQL进阶教程》学习记录--GROUP BY、PARTITION BY
    PostgreSQL 时间转换
    vlc+flv.js 摄像头 H5 直播
    echarts label formatter params backgroundColor rich 标签设置背景图并传参
    异步、多线程、Await/Async、Task
    “2+3”等于我的自白
    SignalR:React + ASP.NET Core Api
  • 原文地址:https://www.cnblogs.com/shamgod/p/5171339.html
Copyright © 2011-2022 走看看