可以定义一个实体类,封装需要导出为Excel表格的数据,加
@Excel(name = "批次编号", width = 15)
注解,然后在通过查询,查出实体类对应的数据,表头已经通过name写好了,然后在controller直接写导出就行了
@Autowired
private IClCaseInfoService clCaseInfoService;
/**
* 导出excel
*
*/
@ApiOperation(value="***", notes="***")
@RequestMapping(value = "/export")
public ModelAndView exportCaseCollectionExcel(ClCaseInfo clCaseInfo,HttpServletRequest request) {
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
List<ClCaseInfoExport> exportList = clCaseInfoService.getClCaseInfoExportList();
String fileName="***";
String date = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
fileName=fileName+date;
// 导出文件名称
mv.addObject(NormalExcelConstants.FILE_NAME,"fileName");
// 注解对象Class
mv.addObject(NormalExcelConstants.CLASS, ClCaseInfoExport.class);
// 自定义表格参数
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams());
// 导出数据列表
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
return mv;
}
如果导出的文件名称未生效,检查是否是前端已经写死了