查询订单的详情
只有未付款的订单,点击"付款",跳转到订单的详情页面
步骤分析:
1.在订单列表,点击付款,
/store/order?method=getById&oid=?
2.在orderservlet中编写getById()
接受oid
调用service 返回Order
将order放入域中,请求转发 order_info.jsp
3.orderDao中 通过一个订单号,查询订单详情
select * from orderitem oi,product p where oi.pid = p.pid and oi.oid = ?
用mapListhandler封装结果集,然后使用BeanUtils封装成指定的bean对象 ,添加到order的items中即可
---------------------------------------------------------------------------------------------------------------
<th colspan="5">订单编号:${bean.oid } 订单金额:${o.total } <c:if
test="${o.state==0 }">
<a href="${pageContext.request.contextPath }/order?method=getById&oid=${o.oid}">付款</a>
</c:if> <c:if test="${o.state==1 }">
<a>已付款</a>
</c:if> <c:if test="${o.state==2 }">
<a>确认收获</a>
</c:if> <c:if test="${o.state==3 }">
<a>已完成</a>
</c:if>
</th>
---------------------------------------------------------------------------------------------------------------
OrderServlet
/**
* 查询订单详情
* @param request
* @param response
* @return
* @throws Exception
*/
public String getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
//获取id
String oid=request.getParameter("oid");
//调用service 层 通过oid 返回order
OrderService os=(OrderService) BeanFactory.getBean("OrderService");
Order order=os.getById(oid);
//将order 放入域中 页面跳转
request.setAttribute("bean",order);
return "/jsp/order_info.jsp";
}
---------------------------------------------------------------------------------------------------------------
package com.feizhu.service;
import com.feizhu.domain.Order;
import com.feizhu.domain.PageBean;
import com.feizhu.domain.User;
public interface OrderService {
void add(Order order) throws Exception;
PageBean<Order> findAllByPage(int currPage, int pageSize, User user)throws Exception;
Order getById(String oid) throws Exception;
void updateOrder(Order order)throws Exception;
}
---------------------------------------------------------------------------------------------------------------
OrderServiceImpl
/**
* 查看订单详情
*/
@Override
public Order getById(String oid) throws Exception {
//调用OrderDao层 返回一个 order
OrderDao od=(OrderDao) BeanFactory.getBean("OrderDao");
return od.getById(oid);
}
---------------------------------------------------------------------------------------------------------------
OrderDaoImpl
/**
* 查询订单详情
*/
@Override
public Order getById(String oid) throws Exception {
QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
String sql="select *from orders where oid=?";
Order order= qr.query(sql, new BeanHandler<>(Order.class),oid);
//封装ordertimes
sql="select * from orderitem oi,product p where oi.pid=p.pid and oi.oid=?";
List<Map<String,Object>> query = qr.query(sql, new MapListHandler(),oid);
for (Map<String, Object> map : query) {
//封装product
Product product=new Product();
BeanUtils.populate(product, map);
//封装orderitem
OrderItem oi=new OrderItem();
BeanUtils.populate(oi, map);
oi.setProduct(product);
//将orderitem加入order的items中
order.getItems().add(oi);
}
return order;
}
---------------------------------------------------------------------------------------------------------------
order_info.jsp
<div style="margin: 0 auto; margin-top: 10px; width: 950px;">
<strong>订单详情</strong>
<table class="table table-bordered">
<tbody>
<tr class="warning">
<th colspan="5">订单编号:${bean.oid }</th>
</tr>
<tr class="warning">
<th>图片</th>
<th>商品</th>
<th>价格</th>
<th>数量</th>
<th>小计</th>
</tr>
<c:forEach items="${bean.items }" var="oi">
<tr class="active">
<td width="60" width="40%"><input type="hidden" name="id"
value="22"> <img
src="${pageContext.request.contextPath}/${oi.product.pimage}"
width="70" height="60"></td>
<td width="30%"><a target="_blank"> ${oi.product.pname }...</a>
</td>
<td width="20%">¥${oi.product.shop_price }</td>
<td width="10%">${oi.count }</td>
<td width="15%"><span class="subtotal">¥${oi.subtotal }</span>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div style="text-align: right; margin-right: 120px;">
商品金额: <strong style="color: #ff6600;">¥${bean.total }元</strong>
</div>
</div>
------------------------------------------------------------------------------------------------------------
备注:由于个人原因,本博客暂停更新。如有问题可联系本人,本人提供技术指导、学习方向、学习路线。本人微信wlp1156107728(添加注明来意) QQ1156107728(添加注明来意)
本文介绍了查询未付款订单并跳转至订单详情页的流程。用户点击"付款",系统通过 orderId 调用 `getById()` 方法,从 `OrderService`、`OrderDao` 获取订单详情,包括订单编号、金额等信息。根据订单状态,展示不同的操作链接,如"付款"、"已付款"、"确认收获"和"已完成"。整个流程涉及 Servlet、Service、Dao 层交互,以及 JSP 页面展示。
2436

被折叠的 条评论
为什么被折叠?



