add<个人订单页>

master
liyansheng 2024-12-21 17:09:41 +08:00
parent 68304201e5
commit ddfc9270aa
6 changed files with 72 additions and 0 deletions

View File

@ -29,6 +29,9 @@ public class OrdersServlet extends HttpServlet {
case "all":
ordersService.allOrder(req, resp);
break;
case "my":
ordersService.myOrder(req, resp);
break;
case "add":
try {
ordersService.checkOrder(req, resp);

View File

@ -37,4 +37,14 @@ public class OrdersDao {
}
return 0;
}
public List<Orders> getMyOrders(int userId) {
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark from orders o where user_id =?";
try {
return queryRunner.query(sql, new BeanListHandler<>(Orders.class),userId);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -13,4 +13,6 @@ public interface IOrdersService {
void checkOrder(HttpServletRequest req, HttpServletResponse resp) throws Exception;
int addOrder(int userId,double price, String address, String remark);
void myOrder(HttpServletRequest req, HttpServletResponse resp);
}

View File

@ -51,4 +51,16 @@ public class OrdersServiceImpl implements IOrdersService {
return ordersDao.addOrder(userId,price,address,remark);
}
@Override
public void myOrder(HttpServletRequest req, HttpServletResponse resp) {
User user = (User) req.getSession().getAttribute("user");
List<Orders> Orders = ordersDao.getMyOrders(user.getId());
req.setAttribute("Orders",Orders);
try {
req.getRequestDispatcher("myOrder.jsp").forward(req,resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -10,6 +10,7 @@
<a href="/cart?action=list">我的购物车</a>
<a href="/orders?action=all">所有订单</a>
<a href="/logout">注销登录</a>
<a href="/orders?action=my">我的订单</a>
</c:if>
<c:if test="${sessionScope.user == null}">
<p>请登录后查看更多内容~</p>

View File

@ -0,0 +1,44 @@
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我的订单</title>
</head>
<body>
<h1>我的订单</h1>
<table border="1">
<thead>
<tr>
<th>订单编号</th>
<th>用户ID</th>
<th>订单日期</th>
<th>总金额</th>
<th>地址</th>
<th>商品信息</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="order" items="${Orders}">
<tr>
<td>${order.id}</td>
<td>${order.userId}</td>
<td>${order.orderDate}</td>
<td>${order.totalPrice}</td>
<td>${order.address}</td>
<td>${order.remark}</td>
<td>
<a href="/orders?action=delete&id=${order.id}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<br/>
<br>
<a href="/">主页</a>
</body>
</html>