实体类展示
@Data @AllArgsConstructor @NoArgsConstructor public class GodownEntryCopyPage { /** * 客户名称 */ @ExcelProperty("") private String customName; /** * 产品型号 */ @ExcelProperty("") private String productModel; /** * 产品规格 */ @ExcelProperty("") private String productSpecifications; /** * 数量 */ @ExcelProperty("") private Double qty; @ExcelProperty("") private String particulars; /** * 颜色 */ @ExcelProperty("") private String color; /** * 盘数 */ @ExcelProperty("") private Double qtyOfDisks; /** * 盘形 */ @ExcelProperty("") private String disk; @ExcelProperty("") private String remark; @ExcelProperty("") private String groupLabel; /** * 材料 */ @ExcelProperty("") private String material; /** * 批次编号 */ @ExcelProperty("") private String batchInformation; /** * 加工类型 */ @ExcelProperty("") private String processingType; /** * 客户送货单号 */ @ExcelProperty("") private String deliveryNumber; /** * 外径 */ @ExcelProperty("") private String od; /** * 接头 */ @ExcelProperty("") private String splice; @ExcelProperty("") private String oneValue; @ExcelProperty("") private String twoValue; @ExcelProperty("") private String threeValue; @ExcelProperty("") private String fourValue; @ExcelProperty("") private String fiveValue; @ExcelProperty("") private String sixValue; @ExcelProperty("") private String sevenValue; @ExcelProperty("") private String eightValue; @ExcelProperty("") private String nineValue; @ExcelProperty("") private String tenValue; } 业务层 public void download(HttpServletResponse response,HttpServletRequest request) throws IOException { // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 String fileName = URLEncoder.encode("测试", "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); EasyExcel.write(response.getOutputStream(), GodownEntryCopyPage.class).head(dealWithHeads()).sheet("入库单").doWrite(data(request)); } public List<List<String>> dealWithHeads() { List<List<String>> listParent = new ArrayList<>(); CusInfoMaintainCopyDO cusInfoMaintainCopyDOS =cusInfoMaintainCopyMapper.selectListPage(); listParent.add(Arrays.asList("客户名称(必填)","产品型号(必填)","产品规格(必填)","数量(必填)", "明细","颜色","盘数(必填)","盘形(必填)","备注","分组标签","材料(必填)","批次编号","加工类型","客户送货单号", "外径","接头", cusInfoMaintainCopyDOS.getKeyOne(),cusInfoMaintainCopyDOS.getKeyTwo(),cusInfoMaintainCopyDOS.getKeyThree(),cusInfoMaintainCopyDOS.getKeyFour(),cusInfoMaintainCopyDOS.getKeyFive(), cusInfoMaintainCopyDOS.getKeySix(),cusInfoMaintainCopyDOS.getKeySeven(),cusInfoMaintainCopyDOS.getKeyEight(),cusInfoMaintainCopyDOS.getKeyNine(),cusInfoMaintainCopyDOS.getKeyTen())); return xzHeadFields(listParent); } private List<GodownEntryCopyPage> data(HttpServletRequest request) { // 过滤选中数据 String selections = request.getParameter("selections"); List<GodownEntryCopyDO> GodownEntryDOList=new ArrayList<>(); List<String> selectionList = Arrays.asList(selections.split(",")); for (String s:selectionList){ GodownEntryCopyDO godownEntryDO = godownEntryCopyMapper.GordonById(s); GodownEntryDOList.add(godownEntryDO); } List<GodownEntryCopyPage> pageList = new ArrayList<>(); for (GodownEntryCopyDO card : GodownEntryDOList) { if (card!=null) { GodownEntryCopyPage vo = new GodownEntryCopyPage(); BeanUtils.copyProperties(card, vo); List<InWarehouseCopyDO> InWarehouseDOs = godownEntryCopyMapper.getSonByParentId(card.getId()); for (InWarehouseCopyDO inWarehouseDO:InWarehouseDOs){ vo.setOneValue(inWarehouseDO.getOneValue()); vo.setTwoValue(inWarehouseDO.getTwoValue()); vo.setThreeValue(inWarehouseDO.getThreeValue()); vo.setFourValue(inWarehouseDO.getFourValue()); vo.setFiveValue(inWarehouseDO.getFiveValue()); vo.setSixValue(inWarehouseDO.getSixValue()); vo.setSevenValue(inWarehouseDO.getSevenValue()); vo.setEightValue(inWarehouseDO.getEightValue()); vo.setNineValue(inWarehouseDO.getNineValue()); vo.setTenValue(inWarehouseDO.getTenValue()); } pageList.add(vo); } } return pageList; }