开发者学堂课程【Java Web项目实战2:图书商城:订单模块之加载订单完成 】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/35/detail/786
订单模块之加载订单完成
内容简介:
一、流程
二、开发路径
一、流程
/jsps/order/list.jsp
金额:138.8 付款 oid
OrderServlet#load0
1.获取 oid
2.通过 oid 来调用 service 得到 Order
3.保存到 request 域,转发到 desc.jsp 显示
request:Order
/jsps/order/desc.jsp
显示订单
二、开发路径
<h1>我的订单</h1>
<table border="1" width="100"cellspacing="0" background="black"
<c:forEach items="s(orderList )”var="oder">
<tr bgcolor="gray" bordercolor="gray">
<tdcolspan="6>
订单编号:$(order.oid) 成交时间:$(order.ordertime) 金额:<font color="red”
<c:choose>
<c:whentest="$(order.state eq 1)">
<ahref="<c:url value='/jsps/order/ieso.jsp'/>付款</a>
</c:when>
<c:whentest="s(order.state eq 2 )”>等待发货</c:when>
<c:whentest="$[order.state eq 3]>
<a href="javascript:alert(·已确认收货1);”确认收货</a>
</c:when>
<c:when test="(order.state eq 4)”>交易成功</c:when>
</c:choose>
</td>
</tr>
<c:forEachitems="s[order.orderItemList”var="orderItem"
<bordercolor="gray" align="center">
我的订单
@param request
@param response I
@return
Athrows ServletException
throws IOException
publicString myOrders
(HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException [
★1. 从session得到当前用户,再获取其uid
★2. 使用uid调用orderservice#myorders(uid)得到该用户的所有订单Liat<order>
★3.把订单列表保存到request域中,转发到/jsps/order/list.jsp
User user (User) request.getSession().getAttribute("session_user"); List<order> orderList = orderService.myorders(user.getUid());
request.setAttribute("orderList", orderList);
zeturn"f:/jsps/order/list.jsp";
把一个Map转换成一个orderItem对象
@param map
@return
privateOrderItemtoOrderItem(Map<String, Object> map)
OrderItem orderItem = CommonUtils.toBean(map, OrderItem.class);
Book book = CommonUtils.toBean(map, Book.class);
orderItem.setBook (book) ;
return orderItem;
加载订单 I
@param oid
@return
public Order load(String oid) (
try[
★1.得到当前用户的所有订单
+/
String sql="select from orders where oid=?";
Order order =qr.query(sql, new BeanHandler<order>(Order.class), oid);
★2.为order加载它的所有条目
loadorderItems(order); I
★3.返回订单列表
*/
return order;
1catch (SQLException e)(
throw new RuntimeException(e);