1:引入jia包:在pom.xml中引入一下jia包:
cn.afterturn
easypoi-base
4.1.0
cn.afterturn
easypoi-web
4.1.0
cn.afterturn
easypoi-annotation
4.1.0
2:代码如下:
代码(一):Controller请求
/**
* 导出数据
*
* @param workOrderQuery
* @param modelMap
* @param response
* @param request
*/
@RequestMapping(value = "/exportWorkOrder", method = RequestMethod.POST)
public void exportWorkOrder(WorkOrderQuery workOrderQuery, ModelMap modelMap, HttpServletResponse response, HttpServletRequest request) {
workOrderService.exportWorkOrder(workOrderQuery , modelMap, response, request);
}
代码二:接口
void exportWorkOrder(WorkOrderQuery workOrderQuery , ModelMap modelMap, HttpServletResponse response, HttpServletRequest request);
代码三:实现类:导出,只要引入上面的jia包。所有的功能都在里面,直接使用即可。
@Override
public void exportWorkOrder(WorkOrderQuery workOrderQuery, ModelMap modelMap, HttpServletResponse response, HttpServletRequest request) {
List workOrderExcelDTOS = myWorkOrderMapper.getWorkOrderExcelList(workOrderQuery);//查询数据 List集合
Assert.isTrue(workOrderExcelDTOS.size() == 0, ResultCodeEnum.NO_DATA_CAN_BE_EXPORTED);
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF);
//exportParams.setAddIndex(true);
modelMap.put(NormalExcelConstants.DATA_LIST, workOrderExcelDTOS);//查询出来的List数据
modelMap.put(NormalExcelConstants.CLASS, WorkOrderExcelDTO.class);//实例化
modelMap.put(NormalExcelConstants.PARAMS, exportParams);//传递的参数
modelMap.put(NormalExcelConstants.FILE_NAME, "work-order");//导出表的名称
PoiBaseView.render(modelMap, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);//调用封装好的的方法:直接导出即可,这个是调用的普通的导出,还可以使用导出大量的数据,到时候可以点进去看看源码。
}
导出的字段实体:
public class WorkOrderExcelDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Excel(name = "工单编号", width = 15)
private String workOrderNum;
@Excel(name = "订单编号", width = 15)
private String orderNum;
@Excel(name = "订单发货时间", width = 25, format = "yyyy-MM-dd HH:mm:ss")
private Date successTime;
@Excel(name = "创建时间", width = 25, format = "yyyy-MM-dd HH:mm:ss")
private Date createDate;
@Excel(name = "实际完结时间", width = 25, format = "yyyy-MM-dd HH:mm:ss")
private Date actualCompletionDate;
@Excel(name = "工单类型", width = 15, replace = {"异常-超时未处理_0", "咨询-发货无物流_1", "咨询-物流停滞_2", "咨询-物流流转_3", "咨询-错发/漏发_4",
"咨询-补货款差价_5", "咨询-订单状态异常_6", "咨询-配件缺失_7", "咨询-退货少件_8", "咨询-商品下架_9", "咨询-协商退货_10", "赔付-退运费_11",
"赔付-退货款差价_12", "赔付-商品质量问题_13", "赔付-破损_14", "赔付-补偿安慰_15", "退货退款-无理由退货退款_16", "仲裁-用户发起仲裁_17",
"投诉-公司投诉_18", "投诉-媒体/工商投诉_19", "投诉-服务态度_20", "投诉-服务效率_21", "退货退款-商品质量问题_22", "咨询-退货异常_23",
"异常-拦截异常_24", "技术-推送云仓销售出库单失败_25", "技术-推送云仓退货入库单失败_26", "异常-回寄异常_27", "异常-退货异常_28", "异常-超时未确认收货_29"
})
private Integer workOrderType;
@Excel(name = "工单状态", width = 15, replace = {"待认领_0", "跟进中_1", "已完结_2", "待跟进_3"})
private Integer status;
@Excel(name = "所属技能组", width = 15)
private String groupName;
@Excel(name = "负责人", width = 15)
private String responsiblePerson;
@Excel(name = "创建人", width = 15)
private String createName;
@Excel(name = "供应商家", width = 15)
private String otherName;
@Excel(name = "用户手机号", width = 15)
private String mobile;
@Excel(name = "收货人姓名", width = 15)
private String name;
@Excel(name = "收货人手机号", width = 15)
private String phone;
@Excel(name = "收货人地址", width = 15)
private String address;
}
可以参考如下链接:EasyPoi教程:
http://easypoi.mydoc.io/#text_221144