###创建公共页面
1:左侧功能目录页面:
resources\templates\common\nav.ftl
2:成功跳转页面:
resources\templates\common\success.ftl
成功提示
成功!
${msg!""}!3S后自动跳转
<#--${msg!""} :判断为空的话 就复制一个空值-->
3:错误跳转页面:
resources\templates\common\error.ftl
错误提示
错误!
${msg!""}! Best check yo self, you're not looking too good. 3S后自动跳转
###实现orderservice的findList查询所有订单的方法
com\imooc\service\imp\OrderServiceImp.java
Override
public Page<OrderDTO> findList(Pageable pageable) {
Page<OrderMaster> orderMasterPage = orderMasterDao.findAll(pageable);
/*Page转成List*/
List<OrderDTO> orderDTOList = OrderMaster2OrderDTOConverter.convert(orderMasterPage.getContent());
/*封装成page对象*/
Page<OrderDTO> orderDTOPage = new PageImpl<OrderDTO>(orderDTOList,pageable,orderMasterPage.getTotalElements());
return orderDTOPage;
}
###创建controller控制层
com\imooc\controller\SellerOrderController.java
package com.imooc.controller;
import com.imooc.dto.OrderDTO;
import com.imooc.exception.SellException;
import com.imooc.service.OrderService;
import com.imooc.vo.enums.ResultEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.Map;
/**
* @author: menghaibin
* @create: 2020-02-22 20:15
* @description: 卖家端订单
**/
Controller
RequestMapping("/seller/order")
@Slf4j
public class SellerOrderController {
@Autowired
private OrderService orderService;
}
1:查询所有订单:
/*后台查询订单列表
* page:第几页
* size:一页有多少条数据
* */
@GetMapping("/list")
public ModelAndView list(@RequestParam(value = "page",defaultValue = "1") Integer page,
@RequestParam(value = "size",defaultValue = "3") Integer size,
Map<String,Object> map){
PageRequest request = new PageRequest(page-1,size);
Page<OrderDTO> orderDTOPage = orderService.findList(request);
map.put("orderDTOPage",orderDTOPage);
map.put("currentPage",page);/*当前页,用于前端分页*/
map.put("size",size);/*每页多少条*/
return new ModelAndView("/list",map);
}
创建list方法需要返回的list的页面:
resources\templates\list.ftl
卖家商品列表
<#--侧边栏样式-->
<#--左侧功能侧栏-->
<#include "common/nav.ftl" >
<#--主内容-->
订单id
姓名
手机号
地址
金额
订单状态
支付状态
创建时间
操作
<#--遍历获取订单列表-->
<#list orderDTOPage.getContent() as orderDTO>
${orderDTO.orderId}
${orderDTO.buyerName}
${orderDTO.buyerPhone}
${orderDTO.buyerAddress}
${orderDTO.orderAmount}
${orderDTO.orderStatus}
${orderDTO.payStatus}
${orderDTO.createTime}
详情
<#if orderDTO.orderStatus == 0 >
取消
#if>
#list>
预览页面:
http://127.0.0.1/sell/seller/order/list
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Y5oyexZf-1584602629914)(./1583569620698.png)]
2:列表分页功能:
在list.ftl中追加分页组件的html代码
resources\templates\list.ftl
3:取消订单功能:
在SellerOrderController中追加cancel订单取消方法
/*取消订单*/
@GetMapping("/cancel")
public ModelAndView cancel(@RequestParam("orderId") String orderId,
Map<String,Object> map){
try{
/*订单如果不存在 在findone方法里已经做了判断 会抛出异常*/
OrderDTO orderDTO = orderService.findOne(orderId);
orderService.cancel(orderDTO);
}catch(SellException e){
log.error("订单不存在 取消订单失败");
map.put("msg", e.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/error",map);
}
map.put("msg", ResultEnum.SUCCESS.getMsg());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/success",map);
}
在list页面已经有了取消订单的连接:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M2xCxOpz-1584602629915)(./1583570266656.png)]
4:订单详细功能:
在SellerOrderController中追加detail订单取消方法
/*订单详情*/
@GetMapping("/detail")
public ModelAndView detail(@RequestParam("orderId") String orderId,
Map<String,Object> map){
OrderDTO orderDTO = new OrderDTO();
try{
/*订单如果不存在 在findone方法里已经做了判断 会抛出异常*/
orderDTO = orderService.findOne(orderId);
}catch(SellException e){
log.error("订单不存在 取消订单失败");
map.put("msg", e.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/error",map);
}
map.put("orderDTO",orderDTO);
return new ModelAndView("order/detail",map);
}
创建detail方法需要返回的detail.ftl的页面:
resources\templates\order\detail.ftl
卖家订单详细页
<#--侧边栏样式-->
<#--侧栏-->
<#include "../common/nav.ftl" >
<#--主内容-->
订单id
订单总金额
${orderDTO.orderId}
${orderDTO.orderAmount}
商品id
商品名称
商品价格
数量
总额
<#list orderDTO.orderDetailList as orderDetail>
${orderDetail.productId}
${orderDetail.productName}
${orderDetail.productPrice}
${orderDetail.productQuantity}
${orderDetail.productPrice*orderDetail.productQuantity}
#list>
预览页面:在列表页中点击详情
http://127.0.0.1/sell/seller/order/list
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vWYTeWBE-1584602629917)(./1583570628608.png)]
5:订单完结的功能:
在SellerOrderController中追加finish订单取消方法
/*完结订单*/
@GetMapping("/finish")
public ModelAndView finish(@RequestParam("orderId") String orderId,
Map<String,Object> map){
OrderDTO orderDTO;
try{
orderDTO = orderService.findOne(orderId);/*订单如果不存在 在findone方法里已经做了判断 会抛出异常*/
orderService.finish(orderDTO);
}catch(SellException e){
log.error("订单不存在 完结订单失败");
map.put("msg", e.getMessage());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/error",map);
}
map.put("msg", ResultEnum.SUCCESS.getMsg());
map.put("url","/sell/seller/order/list");
return new ModelAndView("common/success",map);
}