1 订单查询
准备工作
修改订单管理链接
未付款订单,state=1
已付款订单,state=2
已发货的订单,state=3
已完成的订单,state=4
- d.add('0105','01','订单管理');
- d.add('010501','0105','订单管理','${pageContext.request.contextPath}/adminOrderServlet?method=findAllOrders','','mainFrame');
- d.add('010502','0105','未付款的订单','${pageContext.request.contextPath}/adminOrderServlet?method=findAllOrders&state=1','','mainFrame');
- d.add('010503','0105','已付款订单','${pageContext.request.contextPath}/adminOrderServlet?method=findAllOrders&state=2','','mainFrame');
- d.add('010504','0105','已发货的订单','${pageContext.request.contextPath}/adminOrderServlet?method=findAllOrders&state=3','','mainFrame');
- d.add('010505','0105','已完成的订单','${pageContext.request.contextPath}/adminOrderServlet?method=findAllOrders&state=4','','mainFrame');
复制代码- public String findAllOrders(HttpServletRequest req, HttpServletResponse resp)throws Exception {
- OrderService OrderService =newOrderServiceImp();
- String st = req.getParameter("state");
- List<Order> list = null;if(null == st ||"".equals(st)){//获取到全部订单
- list = OrderService.findAllOrders();}else{
- list = OrderService.findAllOrders(st);}//将全部订单放入request
- req.setAttribute("allOrders", list);//转发 /admin/order/list.jspreturn"/admin/order/list.jsp";}
复制代码- public List<Order>findAllOrders()throws Exception {return orderDao.findAllOrders();}
复制代码- public List<Order>findAllOrders(String st)throws Exception {return orderDao.findAllOrders(st);}
复制代码- public List<Order>findAllOrders(){
- String sql ="select * from orders";return template.query(sql,newBeanPropertyRowMapper<>(Order.class));}
复制代码- public List<Order>findAllOrders(String st){
- String sql ="select * from orders where state= ?";return template.query(sql,newBeanPropertyRowMapper<>(Order.class), st);}
复制代码- <tr
- style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; HEIGHT: 25px; BACKGROUND-COLOR: #afd1f3"><td align="center" width="5%">
- 序号
- </td><td align="center" width="25%">
- 订单编号
- </td><td align="center" width="5%">
- 订单金额
- </td><td align="center" width="5%">
- 收货人
- </td><td align="center" width="5%">
- 订单状态
- </td><td align="center" width="55%">
- 订单详情
- </td></tr><c:if test="${empty allOrders }"><tr><td colspan="6">暂无数据</td></tr></c:if><c:if test="${not empty allOrders }"><c:forEach items="${allOrders}" var="o" varStatus="status"><tr onmouseover="this.style.backgroundColor = 'white'"
- onmouseout="this.style.backgroundColor = '#F5FAFE';"><td style="CURSOR: hand; HEIGHT: 22px" align="center"
- width="5%">
- ${status.count}</td><td style="CURSOR: hand; HEIGHT: 22px" align="center"
- width="25%">
- ${o.oid}</td><td style="CURSOR: hand; HEIGHT: 22px" align="center"
- width="5%">
- ${o.total}</td><td style="CURSOR: hand; HEIGHT: 22px" align="center"
- width="5%">
- ${o.name}</td><td style="CURSOR: hand; HEIGHT: 22px" align="center"
- width="5%"><!--1=未付款、2=发货、3=已发货、4=订单完成 --><c:if test="${o.state==1}">未付款</c:if><c:if test="${o.state==2}"><a href="${pageContext.request.contextPath}/adminOrderServlet?method=updateOrderByOid&oid=${o.oid}">发货</a></c:if><c:if test="${o.state==3}">已发货,未签收</c:if><c:if test="${o.state==4}">完毕</c:if></td><td align="center" style="HEIGHT: 22px"><input type="button" value="订单详情"class="btn" id="${o.oid}"/><table width="100%" border="1"class="myTb"><!--<tr><th>商品</th><th>名称</th><th>数量</th><th>小计</th></tr><tr><td></td><td>名称</td><td>数量</td><td>小计</td></tr><tr><td></td><td>名称</td><td>数量</td><td>小计</td></tr>--></table></td></tr></c:forEach></c:if>
复制代码 2 发货
- <c:if test="${o.state==2}"><a href="${pageContext.request.contextPath}/adminOrderServlet?method=updateOrderByOid&oid=${o.oid}">发货</a></c:if>
复制代码- public String updateOrderByOid(HttpServletRequest req, HttpServletResponse resp)throws Exception {//获取订单ID
- String oid = req.getParameter("oid");//根据订单ID查询订单
- OrderService OrderService =newOrderServiceImp();
- Order order = OrderService.findOrderByOid(oid);//设置订单状态
- order.setState(3);//修改订单信息
- OrderService.updateOrder(order);//重新定向到查询已发货订单
- resp.sendRedirect(req.getContextPath()+"/adminOrderServlet?method=findAllOrders&state=3");return null;}
复制代码- publicvoidupdateOrder(Order order)throws Exception {
- orderDao.updateOrder(order);}
复制代码- publicvoidupdateOrder(Order order){
- String sql ="UPDATE orders SET ordertime=? ,total=? ,state= ?, address=?,NAME=?, telephone =? WHERE oid=?";
- Object[] params ={order.getOrdertime(), order.getTotal(), order.getState(), order.getAddress(), order.getName(), order.getTelephone(), order.getOid()};
- template.update(sql, params);}
复制代码 3 查看订单详情
- <script>
- $(function (){//页面加载完毕之后获取款式为.btn标签,为其绑定点击事件
- $(".btn").click(function (){//获取按钮文字
- var val = $(this).val();//this.value//获取按钮上id的值
- var id =this.id;//alert(id);//获取按钮,约定:假设我们用的是JQUERYAPI获取到的对象,加前缀$.
- var $btn = $(this);if("订单详情"== val){//发送Ajax恳求
- $.post("${pageContext.request.contextPath}/adminOrderServlet",{"method":"findOrderByOidWithAjax","oid": id
- }, function (dt){//alert(dt);//var $tb=$(this).next();//alert(this); //此处无用,JS打印对象:都是Object//console.log(this); //火狐控制台下打印当前对象//获取到当前按钮的下一个兄弟节点
- var $tb = $btn.next("table");//清空table元素
- $tb.html("");//alert($tb.attr("class")); //测试是否正确获取到table标签对象
- $tb.append("<tr><th>商品</th><th>名称</th><th>数量</th><th>小计</th></tr>");//JQUERY的方式遍历数组元素
- $.each(dt, function (i, o){
- var tr ="<tr><td><img src='${pageContext.request.contextPath}/"+ o.product.pimage +"' width='50px'/></td><td>"+ o.product.pname +"</td><td>"+ o.quantity +"</td><td>"+ o.total +"</td></tr>";
- $tb.append(tr);});//更改按钮文字
- $btn.val("关闭");});}if("关闭"== val){
- var $tb = $btn.next("table");
- $tb.html("");
- $btn.val("订单详情");}});});</script>
复制代码编写findOrderByOidWithAjax方法
- public String findOrderByOidWithAjax(HttpServletRequest req, HttpServletResponse resp)throws Exception {//效劳端获取到订单ID,
- String oid = req.getParameter("oid");//查询这个订单下所有的订单项以及订单项对应的商品信息,返回集合
- OrderService OrderService =newOrderServiceImp();
- Order order = OrderService.findOrderByOid(oid);//将返回的集合转换为JSON格式字符串,响应到客户端
- String jsonStr = JSONArray.fromObject(order.getList()).toString();//响应到客户端
- resp.setContentType("application/json;charset=utf-8");
- resp.getWriter().println(jsonStr);return null;}
复制代码 |