java 导出页面数据
【代码】java 导出页面数据。
·
@GetMapping("/export")
@ApiOperation(value = "导出", notes = "导出")
public void export(HttpServletResponse response) throws IOException {
try {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("aaa.xlsx", "UTF-8"));
// 查询条件
TradeEntInfoDto dto = new TradeEntInfoDto();
dto.setAuditStatus("06");
dto.setPageSize(-1);
MybatisPlusPager<TradeEntInfoVo> data = tradeEntInfoService.page(dto);
EasyExcel.write(response.getOutputStream(), TradeEntInfoVo.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.sheet("sheet1").doWrite(data.getRecords());
} catch (Exception e) {
// 重置response
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
Map<String, Object> map = new HashMap<>(2);
map.put("code", ResultCode.CODE_C0400.getCode());
map.put("message", "下载文件失败" + e.getMessage());
response.getWriter().println(JacksonUtil.mapToJson(map));
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)