导出列表数据

 1.建立 ExcelUtiles操作类: 定义导出方法defaultExport

/**
* 默认的 excel 导出
*
* @param list 数据
* @param pojoClass pojo类型
* @param fileName 文件名称
* @param response
* @param exportParams 导出参数
*/
private static void defaultExport(List<?> list, Class<?> pojoClass, String fileName, HttpServletResponse response,
ExportParams exportParams) throws IOException {
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
downLoadExcel(fileName, response, workbook);
}

2.封装方法
/**
* excel 导出
*
* @param list 数据
* @param title 标题
* @param sheetName sheet名称
* @param pojoClass pojo类型
* @param fileName 文件名称
* @param response
*/
public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName,
HttpServletResponse response) throws IOException {
defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName, ExcelType.XSSF));
}
3.接口方法调用
@ApiOperation(value = "导出现金发放列表")
@GetMapping("/getCashGrantListByExport")
public ResponseBean getCashGrantListByExport(@Validated GetCashGrantListExport req, HttpServletResponse response) {
try {
List<CashGrantListDto> list = cashGrantService.getCashGrantListByExport(req);
if (list.size() <= 0) {
return ResponseBean.fail("未查询到数据");
} else if (list.size() > 5000) {
return ResponseBean.fail("记录超过5000,请重新选择查询条件");
} else {
ExcelUtils.exportExcel(list, "现金发放列表", "交易信息sheet", RechargeListDto.class, "现金发放列表", response);
return ResponseBean.success();
}
} catch (Exception e) {
logger.error("导出现金发放列表出错", e);
return ResponseBean.fail("导出现金发放列表出错");
}
}
posted @ 2022-03-24 14:24  春天里的桃花  阅读(109)  评论(0编辑  收藏  举报