2023-01-07
一、“我的訂單”功能
(1)找到“我的訂單”的位置
①購物車頁面Cart.html中的第26行
②結算完成頁面Checkout.html中的第45行
將兩個位置中超鏈接的“href”改變設定,寫為
<a href="order?flag=showOrders">我的訂單</a>
(2)在src檔案夾下的“com.hh.servlet.model”中的“OrderServlet”類中創建“showOrders”方法
(3)在src下的“com.hh.service”中的“OrderService”介面中創建方法
//根據用戶的id找訂單資訊 List<Order> findAllOrder(Integer userId);
(4)在src下的“com.hh.service.impl”中的“OrderServiceImpl”實作類對剛剛設定的抽象方法進行實作
(5)在src下的“com.hh.dao”中的“OrderDao”介面中設定方法
List<Order> findAllOrder(Integer userId);
和“OrderService”介面中的方法一樣,
(6)在src下的“com.hh.dao.impl”中的“OrderDaoImpl”類中對OrderDao”介面中的抽象方法進行實作
@Override public List<Order> findAllOrder(Integer userId) { String sql="select order_id orderId,order_sequence orderSequence,create_time createTime,total_count totalCount,total_amount totalAmount,order_status orderStatus,user_id userId from t_order where user_id=?"; return this.getList(Order.class,sql,userId); }
此處主要寫sql陳述句,與資料庫進行連接,
(7)OrderServiceImpl中的"createOrder"方法
@Override public List<Order> findAllOrder(Integer userId) { return orderDao.findAllOrder(userId); }
(7)在“OrderServlet”中的“showOrders”方法
protected void showOrders(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1.獲得當前登錄人的物件(根據當前登錄人的id值去資料查詢) User user = (User)request.getSession().getAttribute("user"); //2.呼叫業務層處理業務 List<Order> allOrder = orderService.findAllOrder(user.getId()); //3.給回應 request.setAttribute("orders",allOrder); this.processTemplate("order/order",request,response); }
(8)在web下的“WEB-INF”的“order”中的“order.html”中進行渲染
設定命名空間、base標簽
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<base th:href="@{/}">
將“../../../”使用“”替換,使用快捷鍵“ctrl+r”
<tbody> <tr th:each="order,status : ${orders}"> <td th:text="${order.orderSequence}">12354456895</td> <td th:text="${order.createTime}"> 2015.04.23 </td> <td th:text="${order.totalCount}">90.00</td> <td th:text="${order.totalAmount}">88</td> <td> <a href="" class="send" th:if="${order.orderStatus==0}">等待發貨</a> <a href="" class="send" th:if="${order.orderStatus==1}">已發貨</a> <a href="" class="send" th:if="${order.orderStatus==2}">確認識訓</a> </td> <td><a href="">查看詳情</a></td> </tr> </tbody>
(9)在重繪服務器后,先登陸后“轉到主頁”,之后將一些圖書加入購物車后,點擊“購物車”圖示,之后點擊“去結算”,點擊右上角“我的訂單”,如果出現訂單號,那么代碼OK
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/541427.html
標籤:其他
下一篇:多載的奧義之函式多載
