企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] # 步骤 1 : 先运行,看到效果,再学习 先将完整的项目(向老师要相关资料),配置运行起来,确认可用之后,再学习做了哪些步骤以达到这样的效果。 # 步骤 2 : 模仿和排错 在确保可运行项目能够正确无误地运行之后,再严格照着教程的步骤,对代码模仿一遍。 模仿过程难免代码有出入,导致无法得到期望的运行结果,此时此刻通过比较**正确答案** ( 可运行项目 ) 和自己的代码,来定位问题所在。 采用这种方式,**学习有效果,排错有效率**,可以较为明显地提升学习速度,跨过学习路上的各个槛。 # 步骤 3 : 准备数据SQL 订单数据,以及其对应的订单项数据,都是由前台功能增加的。 为了在后台演示效果,需要自己在数据库中插入数据 1. 订单: ``` insert into t_order (order_code, address, post, receiver, mobile, user_message, create_date, pay_date, delivery_date, confirm_date, status, user_id) VALUES ('201608241638122609867','某某市,某某区,某某街道,某某号 ','610000','某某某','15111111111',NULL,'2018-08-30',NULL,NULL,NULL,'waitDelivery',1); ``` 注: 倒数第一个参数1是对应的用户id,需要在数据库中存在,请根据自己的数据信息自行修改。 2. 订单项 ``` insert into t_order_item (number, user_id, product_id, order_id) VALUES (2,1,1,1); insert into t_order_item (number, user_id, product_id, order_id) VALUES (3,1,2,1); ``` 注: 第三个参数1、2分别对应的产品id,需要在数据库中存在,请根据自己的数据信息自行修改。 # 步骤 4 : 页面截图 ![](https://box.kancloud.cn/1920f2555e356f3dddf17625ff454fa4_1847x449.png) # 步骤 5:Order.java,OrderItem.java实体类 1\. 与OrderItem的一对多关系 2\. total,totalNumber 这个订单的总金额和总数量 Order ``` package com.dodoke.bean; import java.util.Date; import java.util.List; import com.dodoke.dao.inter.OrderDao; /******************************************************************************* * javaBeans t_order --> TOrder <table explanation> * * @author 2019-01-17 08:35:28 * */ public class Order { // field /** ID **/ private int id; /** 订单编号 **/ private String orderCode; /** 地址 **/ private String address; /** 邮编 **/ private String post; /** 收件人 **/ private String receiver; /** 手机号 **/ private String mobile; /** 买家留言 **/ private String userMessage; /** 创建时间 **/ private Date createDate; /** 支付时间 **/ private Date payDate; /** 发货时间 **/ private Date deliveryDate; /** 确认收货时间 **/ private Date confirmDate; /** 状态 **/ private String status; /** 所属用户 **/ private User user; /** * 订单对应的订单项 */ private List<OrderItem> orderItems; /** * 总价格 */ private float total; /** * 总数量 */ private int totalNumber; // method public int getId() { return id; } public void setId(int id) { this.id = id; } public String getOrderCode() { return orderCode; } public void setOrderCode(String orderCode) { this.orderCode = orderCode; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getPost() { return post; } public void setPost(String post) { this.post = post; } public String getReceiver() { return receiver; } public void setReceiver(String receiver) { this.receiver = receiver; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public String getUserMessage() { return userMessage; } public void setUserMessage(String userMessage) { this.userMessage = userMessage; } public Date getCreateDate() { return createDate; } public void setCreateDate(Date createDate) { this.createDate = createDate; } public Date getPayDate() { return payDate; } public void setPayDate(Date payDate) { this.payDate = payDate; } public Date getDeliveryDate() { return deliveryDate; } public void setDeliveryDate(Date deliveryDate) { this.deliveryDate = deliveryDate; } public Date getConfirmDate() { return confirmDate; } public void setConfirmDate(Date confirmDate) { this.confirmDate = confirmDate; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public List<OrderItem> getOrderItems() { return orderItems; } public void setOrderItems(List<OrderItem> orderItems) { this.orderItems = orderItems; } public float getTotal() { return total; } public void setTotal(float total) { this.total = total; } public int getTotalNumber() { return totalNumber; } public void setTotalNumber(int totalNumber) { this.totalNumber = totalNumber; } /** * 判断订单状态 * * @return */ public String getStatusDesc() { String desc = "未知"; switch (status) { case OrderDao.waitPay: desc = "待付款"; break; case OrderDao.waitDelivery: desc = "待发货"; break; case OrderDao.waitConfirm: desc = "待收货"; break; case OrderDao.waitReview: desc = "等评价"; break; case OrderDao.finish: desc = "完成"; break; case OrderDao.delete: desc = "刪除"; break; default: desc = "未知"; } return desc; } } ``` OrderItem ``` package com.dodoke.bean; /******************************************************************************* * javaBeans t_order_item --> TOrderItem <table explanation> * * @author 2019-01-17 08:35:28 * */ public class OrderItem { // field /** ID **/ private int id; /** 数量 **/ private int number; /** 所属用户 **/ private User user; /** 所属产品 **/ private Product product; /** 所属订单 **/ private Order order; // method public int getId() { return id; } public void setId(int id) { this.id = id; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } } ``` # 步骤 6:DaoUtil 将所有dao实现类,设计为单例模式,写出如下dao工具类 ``` package com.dodoke.util; import com.dodoke.dao.impl.CategoryDaoImpl; import com.dodoke.dao.impl.OrderDaoImpl; import com.dodoke.dao.impl.OrderItemDaoImpl; import com.dodoke.dao.impl.ProductDaoImpl; import com.dodoke.dao.impl.ProductImageDaoImpl; import com.dodoke.dao.impl.PropertyDaoImpl; import com.dodoke.dao.impl.PropertyValueDaoImpl; import com.dodoke.dao.impl.UserDaoImpl; import com.dodoke.dao.inter.CategoryDao; import com.dodoke.dao.inter.OrderDao; import com.dodoke.dao.inter.OrderItemDao; import com.dodoke.dao.inter.ProductDao; import com.dodoke.dao.inter.ProductImageDao; import com.dodoke.dao.inter.PropertyDao; import com.dodoke.dao.inter.PropertyValueDao; import com.dodoke.dao.inter.UserDao; public class DaoUtil { public static CategoryDao categoryDao = CategoryDaoImpl.getInstance(); public static PropertyDao propertyDao = PropertyDaoImpl.getInstance(); public static ProductDao productDao = ProductDaoImpl.getInstance(); public static ProductImageDao productImageDao = ProductImageDaoImpl.getInstance(); public static PropertyValueDao propertyValueDao = PropertyValueDaoImpl.getInstance(); public static UserDao userDao = UserDaoImpl.getInstance(); public static OrderDao orderDao = OrderDaoImpl.getInstance(); public static OrderItemDao orderItemDAO = OrderItemDaoImpl.getInstance(); } ``` # 步骤 7:OrderDao和OrderDaoImpl ``` package com.dodoke.dao.inter; import java.util.List; import com.dodoke.bean.Order; public interface OrderDao { public static final String waitPay = "waitPay"; public static final String waitDelivery = "waitDelivery"; public static final String waitConfirm = "waitConfirm"; public static final String waitReview = "waitReview"; public static final String finish = "finish"; public static final String delete = "delete"; /** * 增加 * * @param order */ public void add(Order order); /** * 删除 * * @param id */ public void delete(int id); /** * 修改 * * @param order */ public void update(Order order); /** * 根据id获取 * * @param id * @return */ public Order get(int id); /** * 订单分页查询 * * @param cid * @param start * @param count * @return */ public List<Order> list(int start, int count); /** * 所有订单 * * @return */ public List<Order> list(); /** * 获取订单总数 * * @return */ public int getTotal(); } ``` OrderDaoImpl ``` package com.dodoke.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.dodoke.bean.Order; import com.dodoke.bean.User; import com.dodoke.dao.inter.OrderDao; import com.dodoke.util.DBUtil; import com.dodoke.util.DaoUtil; import com.dodoke.util.DateUtil; public class OrderDaoImpl implements OrderDao { private static OrderDaoImpl orderDaoImpl = new OrderDaoImpl(); private OrderDaoImpl() { } public static OrderDaoImpl getInstance() { return orderDaoImpl; } @Override public void add(Order bean) { String sql = "insert into t_order (order_code, address, post, receiver, mobile, user_message,create_date, " + "pay_date, delivery_date, confirm_date, status, user_id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);) { ps.setString(1, bean.getOrderCode()); ps.setString(2, bean.getAddress()); ps.setString(3, bean.getPost()); ps.setString(4, bean.getReceiver()); ps.setString(5, bean.getMobile()); ps.setString(6, bean.getUserMessage()); ps.setTimestamp(7, DateUtil.d2t(bean.getCreateDate())); ps.setTimestamp(8, DateUtil.d2t(bean.getPayDate())); ps.setTimestamp(9, DateUtil.d2t(bean.getDeliveryDate())); ps.setTimestamp(10, DateUtil.d2t(bean.getConfirmDate())); ps.setString(11, bean.getStatus()); ps.setInt(12, bean.getUser().getId()); ps.executeUpdate(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { int id = rs.getInt(1); bean.setId(id); } } catch (SQLException e) { e.printStackTrace(); } } @Override public void delete(int id) { String sql = "delete from t_order where id = ?"; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.execute(sql); } catch (SQLException e) { e.printStackTrace(); } } @Override public void update(Order bean) { String sql = "update t_order set address= ?, post=?, receiver=?,mobile=?,user_message=? ,create_date = ? , pay_date =? , delivery_date =?, " + "confirm_date = ? , order_code =?, user_id=?, status=? where id = ?"; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.setString(1, bean.getAddress()); ps.setString(2, bean.getPost()); ps.setString(3, bean.getReceiver()); ps.setString(4, bean.getMobile()); ps.setString(5, bean.getUserMessage()); ps.setTimestamp(6, DateUtil.d2t(bean.getCreateDate())); ps.setTimestamp(7, DateUtil.d2t(bean.getPayDate())); ps.setTimestamp(8, DateUtil.d2t(bean.getDeliveryDate())); ps.setTimestamp(9, DateUtil.d2t(bean.getConfirmDate())); ps.setString(10, bean.getOrderCode()); ps.setInt(11, bean.getUser().getId()); ps.setString(12, bean.getStatus()); ps.setInt(13, bean.getId()); ps.execute(); } catch (SQLException e) { e.printStackTrace(); } } @Override public Order get(int id) { Order bean = new Order(); String sql = "select * from t_Order where id = ?"; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.setInt(1, id); ResultSet rs = ps.executeQuery(); if (rs.next()) { String orderCode = rs.getString("order_code"); String address = rs.getString("address"); String post = rs.getString("post"); String receiver = rs.getString("receiver"); String mobile = rs.getString("mobile"); String userMessage = rs.getString("user_message"); String status = rs.getString("status"); int uid = rs.getInt("user_id"); Date createDate = DateUtil.t2d(rs.getTimestamp("create_date")); Date payDate = DateUtil.t2d(rs.getTimestamp("pay_date")); Date deliveryDate = DateUtil.t2d(rs.getTimestamp("delivery_date")); Date confirmDate = DateUtil.t2d(rs.getTimestamp("confirm_date")); bean.setOrderCode(orderCode); bean.setAddress(address); bean.setPost(post); bean.setReceiver(receiver); bean.setMobile(mobile); bean.setUserMessage(userMessage); bean.setCreateDate(createDate); bean.setPayDate(payDate); bean.setDeliveryDate(deliveryDate); bean.setConfirmDate(confirmDate); User user = DaoUtil.userDao.get(uid); bean.setUser(user); bean.setStatus(status); bean.setId(id); } } catch (SQLException e) { e.printStackTrace(); } return bean; } @Override public List<Order> list() { return list(0, Short.MAX_VALUE); } @Override public int getTotal() { int total = 0; String sql = "select count(*) from t_order"; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ResultSet rs = ps.executeQuery(sql); while (rs.next()) { total = rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } return total; } @Override public List<Order> list(int start, int count) { List<Order> beans = new ArrayList<Order>(); String sql = "select * from t_order order by id desc limit ?,? "; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.setInt(1, start); ps.setInt(2, count); ResultSet rs = ps.executeQuery(); while (rs.next()) { Order bean = new Order(); String orderCode = rs.getString("order_code"); String address = rs.getString("address"); String post = rs.getString("post"); String receiver = rs.getString("receiver"); String mobile = rs.getString("mobile"); String userMessage = rs.getString("user_message"); String status = rs.getString("status"); Date createDate = DateUtil.t2d(rs.getTimestamp("create_date")); Date payDate = DateUtil.t2d(rs.getTimestamp("pay_date")); Date deliveryDate = DateUtil.t2d(rs.getTimestamp("delivery_date")); Date confirmDate = DateUtil.t2d(rs.getTimestamp("confirm_date")); int uid = rs.getInt("user_id"); int id = rs.getInt("id"); bean.setId(id); bean.setOrderCode(orderCode); bean.setAddress(address); bean.setPost(post); bean.setReceiver(receiver); bean.setMobile(mobile); bean.setUserMessage(userMessage); bean.setCreateDate(createDate); bean.setPayDate(payDate); bean.setDeliveryDate(deliveryDate); bean.setConfirmDate(confirmDate); User user = DaoUtil.userDao.get(uid); bean.setUser(user); bean.setStatus(status); beans.add(bean); } } catch (SQLException e) { e.printStackTrace(); } return beans; } } ``` # 步骤 8:OrderItemDao和OrderItemDaoImpl OrderItemDao ``` package com.dodoke.dao.inter; import java.util.List; import com.dodoke.bean.Order; import com.dodoke.bean.OrderItem; public interface OrderItemDao { /** * 为订单设置订单项集合 * * @param os */ public void fill(List<Order> os); public void fill(Order o); public List<OrderItem> listByOrder(int oid); /** * 查询某种订单下所有的订单项 * * @param oid * @param start * @param count * @return */ public List<OrderItem> listByOrder(int oid, int start, int count); } ``` OrderItemDaoImpl ``` package com.dodoke.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.dodoke.bean.Order; import com.dodoke.bean.OrderItem; import com.dodoke.bean.Product; import com.dodoke.bean.User; import com.dodoke.dao.inter.OrderItemDao; import com.dodoke.util.DBUtil; import com.dodoke.util.DaoUtil; public class OrderItemDaoImpl implements OrderItemDao { private static OrderItemDaoImpl daoImpl = new OrderItemDaoImpl(); private OrderItemDaoImpl() { } public static OrderItemDaoImpl getInstance() { return daoImpl; } public void fill(List<Order> os) { for (Order o : os) { List<OrderItem> ois = listByOrder(o.getId()); float total = 0; int totalNumber = 0; for (OrderItem oi : ois) { total += oi.getNumber() * oi.getProduct().getPromotePrice(); totalNumber += oi.getNumber(); } o.setTotal(total); o.setOrderItems(ois); o.setTotalNumber(totalNumber); } } public void fill(Order o) { List<OrderItem> ois = listByOrder(o.getId()); float total = 0; for (OrderItem oi : ois) { total += oi.getNumber() * oi.getProduct().getPromotePrice(); } o.setTotal(total); o.setOrderItems(ois); } public List<OrderItem> listByOrder(int oid) { return listByOrder(oid, 0, Short.MAX_VALUE); } /** * 查询某种订单下所有的订单项 * @param oid * @param start * @param count * @return */ public List<OrderItem> listByOrder(int oid, int start, int count) { List<OrderItem> beans = new ArrayList<OrderItem>(); String sql = "select * from t_order_item where order_id = ? order by id desc limit ?,? "; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.setInt(1, oid); ps.setInt(2, start); ps.setInt(3, count); ResultSet rs = ps.executeQuery(); while (rs.next()) { OrderItem bean = new OrderItem(); int id = rs.getInt(1); int pid = rs.getInt("product_id"); int uid = rs.getInt("user_id"); int number = rs.getInt("number"); Product product = DaoUtil.productDao.get(pid); if (-1 != oid) { Order order = DaoUtil.orderDao.get(oid); bean.setOrder(order); } User user = DaoUtil.userDao.get(uid); bean.setProduct(product); bean.setUser(user); bean.setNumber(number); bean.setId(id); beans.add(bean); } } catch (SQLException e) { e.printStackTrace(); } return beans; } } ``` # 步骤 9:OrderServlet.java 因为订单的增加和删除,都是在前台进行的。 所以OrderServlet提供的是list方法和delivery(发货)方法 ``` package com.dodoke.controller; import java.util.Date; import java.util.List; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.dodoke.bean.Order; import com.dodoke.dao.inter.OrderDao; import com.dodoke.util.DaoUtil; import com.dodoke.util.Page; /** * Servlet implementation class OrderServlet */ @WebServlet("/OrderServlet") public class OrderServlet extends BaseBackServlet { private static final long serialVersionUID = 1L; @Override public String add(HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub return null; } @Override public String delete(HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub return null; } @Override public String edit(HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub return null; } @Override public String update(HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub return null; } /** * 发货 * * @param request * @param response * @return */ public String delivery(HttpServletRequest request, HttpServletResponse response) { int id = Integer.parseInt(request.getParameter("id")); Order o = DaoUtil.orderDao.get(id); o.setDeliveryDate(new Date()); o.setStatus(OrderDao.waitConfirm); DaoUtil.orderDao.update(o); return "@admin_order_list"; } public String list(HttpServletRequest request, HttpServletResponse response, Page page) { List<Order> os = DaoUtil.orderDao.list(page.getStart(), page.getCount()); DaoUtil.orderItemDAO.fill(os); int total = DaoUtil.orderDao.getTotal(); page.setTotal(total); request.setAttribute("os", os); request.setAttribute("page", page); return "admin/listOrder.jsp"; } } ``` # 步骤10:listOrder.jsp ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@include file="../include/admin/adminHeader.jsp"%> <%@include file="../include/admin/adminNavigator.jsp"%> <script> $(function(){ $("button.orderPageCheckOrderItems").click(function(){ var oid = $(this).attr("oid"); $("tr.orderPageOrderItemTR[oid="+oid+"]").toggle(); }); }); </script> <title>订单管理</title> <div class="workingArea"> <h1 class="label label-info" >订单管理</h1> <br> <br> <div class="listDataTableDiv"> <table class="table table-striped table-bordered table-hover1 table-condensed"> <thead> <tr class="success"> <th>ID</th> <th>状态</th> <th>金额</th> <th width="100px">商品数量</th> <th width="100px">买家名称</th> <th>创建时间</th> <th>支付时间</th> <th>发货时间</th> <th>确认收货时间</th> <th width="120px">操作</th> </tr> </thead> <tbody> <c:forEach items="${os}" var="o"> <tr> <td>${o.id}</td> <td>${o.statusDesc}</td> <td>¥<fmt:formatNumber type="number" value="${o.total}" minFractionDigits="2"/></td> <td align="center">${o.totalNumber}</td> <td align="center">${o.user.name}</td> <td><fmt:formatDate value="${o.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td><fmt:formatDate value="${o.payDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td><fmt:formatDate value="${o.deliveryDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td><fmt:formatDate value="${o.confirmDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td> <button oid=${o.id} class="orderPageCheckOrderItems btn btn-primary btn-xs">查看详情</button> <c:if test="${o.status=='waitDelivery'}"> <a href="admin_order_delivery?id=${o.id}"> <button class="btn btn-primary btn-xs">发货</button> </a> </c:if> </td> </tr> <tr class="orderPageOrderItemTR" oid=${o.id}> <td colspan="10" align="center"> <div class="orderPageOrderItem"> <table width="800px" align="center" class="orderPageOrderItemTable"> <c:forEach items="${o.orderItems}" var="oi"> <tr> <td align="left"> <img width="40px" height="40px" src="img/productSingle/${oi.product.firstProductImage.id}.jpg"> </td> <td> <a href="foreproduct?pid=${oi.product.id}"> <span>${oi.product.name}</span> </a> </td> <td align="right"> <span class="text-muted">${oi.number}个</span> </td> <td align="right"> <span class="text-muted">单价:¥${oi.product.promotePrice}</span> </td> </tr> </c:forEach> </table> </div> </td> </tr> </c:forEach> </tbody> </table> </div> <div class="pageDiv"> <%@include file="../include/admin/adminPage.jsp" %> </div> </div> <%@include file="../include/admin/adminFooter.jsp"%> ``` # 步骤 11: 查询功能讲解 访问地址: http://127.0.0.1:8080/tmall_j2ee/admin\_order\_list 即可看到订单查询界面。 admin\_order\_list 导致OrderServlet.list()方法被调用 1\. 分页查询订单信息 2\. 借助orderItemDAO.fill()方法为这些订单填充上orderItems信息 3\. 服务端跳转到admin/listOrder.jsp页面 4\. 在listOrder.jsp借助c:forEach把订单集合遍历出来 5\. 遍历订单的时候,再把当前订单的orderItem订单项集合遍历出来 OrderServlet ``` public String list(HttpServletRequest request, HttpServletResponse response, Page page) { List<Order> os = DaoUtil.orderDao.list(page.getStart(), page.getCount()); DaoUtil.orderItemDAO.fill(os); int total = DaoUtil.orderDao.getTotal(); page.setTotal(total); request.setAttribute("os", os); request.setAttribute("page", page); return "admin/listOrder.jsp"; } ``` listOrder.jsp ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@include file="../include/admin/adminHeader.jsp"%> <%@include file="../include/admin/adminNavigator.jsp"%> <script> $(function(){ $("button.orderPageCheckOrderItems").click(function(){ var oid = $(this).attr("oid"); $("tr.orderPageOrderItemTR[oid="+oid+"]").toggle(); }); }); </script> <title>订单管理</title> <div class="workingArea"> <h1 class="label label-info" >订单管理</h1> <br> <br> <div class="listDataTableDiv"> <table class="table table-striped table-bordered table-hover1 table-condensed"> <thead> <tr class="success"> <th>ID</th> <th>状态</th> <th>金额</th> <th width="100px">商品数量</th> <th width="100px">买家名称</th> <th>创建时间</th> <th>支付时间</th> <th>发货时间</th> <th>确认收货时间</th> <th width="120px">操作</th> </tr> </thead> <tbody> <c:forEach items="${os}" var="o"> <tr> <td>${o.id}</td> <td>${o.statusDesc}</td> <td>¥<fmt:formatNumber type="number" value="${o.total}" minFractionDigits="2"/></td> <td align="center">${o.totalNumber}</td> <td align="center">${o.user.name}</td> <td><fmt:formatDate value="${o.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td><fmt:formatDate value="${o.payDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td><fmt:formatDate value="${o.deliveryDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td><fmt:formatDate value="${o.confirmDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td> <td> <button oid=${o.id} class="orderPageCheckOrderItems btn btn-primary btn-xs">查看详情</button> <c:if test="${o.status=='waitDelivery'}"> <a href="admin_order_delivery?id=${o.id}"> <button class="btn btn-primary btn-xs">发货</button> </a> </c:if> </td> </tr> <tr class="orderPageOrderItemTR" oid=${o.id}> <td colspan="10" align="center"> <div class="orderPageOrderItem"> <table width="800px" align="center" class="orderPageOrderItemTable"> <c:forEach items="${o.orderItems}" var="oi"> <tr> <td align="left"> <img width="40px" height="40px" src="img/productSingle/${oi.product.firstProductImage.id}.jpg"> </td> <td> <a href="foreproduct?pid=${oi.product.id}"> <span>${oi.product.name}</span> </a> </td> <td align="right"> <span class="text-muted">${oi.number}个</span> </td> <td align="right"> <span class="text-muted">单价:¥${oi.product.promotePrice}</span> </td> </tr> </c:forEach> </table> </div> </td> </tr> </c:forEach> </tbody> </table> </div> <div class="pageDiv"> <%@include file="../include/admin/adminPage.jsp" %> </div> </div> <%@include file="../include/admin/adminFooter.jsp"%> ``` # 步骤 12: 发货功能讲解 当订单状态是waitDelivery的时候,就会出现发货按钮 1\. 发货按钮链接跳转到admin\_order\_delivery 2\. OrderServlet.delivery()方法被调用 2.1 根据id获取Order对象 2.2 修改发货时间,设置发货状态 2.3 更新到数据库 2.4 客户端跳转到admin\_order\_list页面 ``` public String delivery(HttpServletRequest request, HttpServletResponse response) { int id = Integer.parseInt(request.getParameter("id")); Order o = DaoUtil.orderDao.get(id); o.setDeliveryDate(new Date()); o.setStatus(OrderDao.waitConfirm); DaoUtil.orderDao.update(o); return "@admin_order_list"; } ``` # 步骤 13 : 增加,修改,删除功能 订单的增加和删除功能交由前台完成,后台不提供