3
@GetMapping("/export2")
public void streamExport2(HttpServletResponse response) throws IOException {
// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
List<ExcelDto> patch2 = Lists.newArrayList();
recordMapper.streamQuery(new QueryWrapper<PersonClockedRecordEntity>(), new ResultHandler<PersonClockedRecordEntity>() {
@SneakyThrows
@Override
public void handleResult(ResultContext<? extends PersonClockedRecordEntity> resultContext) {
final PersonClockedRecordEntity resultObject = resultContext.getResultObject();
ExcelDto excelDto = new ExcelDto();
BeanUtils.copyProperties(resultObject,excelDto);
patch2.add(excelDto);
EasyExcel.write(response.getOutputStream(),ExcelDto.class).autoCloseStream(false)
.sheet("模板").doWrite(patch2);
patch2.clear();
}
});
}
异常提示 可以导出,但是只有一条数据,我怀疑是覆盖了。 建议描述