1. 调用 ExcelExportUtil.exportExcel 导出失败
// 1. 构建导出参数
ExportParams exportParams = new ExportParams(title, sheetName, ExcelType.XSSF);
// 2. 属性拷贝:T -> R
List<R> targetList = failList.stream()
.map(source -> BeanUtil.copyProperties(source, targetClz))
.toList();
// 3. 导出并转 Base64
try (Workbook workbook = ExcelExportUtil.exportExcel(exportParams, targetClz, targetList);
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
workbook.write(out);
return Base64.getEncoder().encodeToString(out.toByteArray());
} catch (Exception e) {
log.error("导出失败数据 Excel 时发生异常", e);
throw new BusinessException("导出失败数据 Excel 时发生异常");
}
2.报错

3.原因
List<R> targetList = failList.stream()
.map(source -> BeanUtil.copyProperties(source, targetClz))
.toList();
使用了 toList() 得到不可变List
4.解决
List<R> targetList = failList.stream()
.map(e -> BeanUtil.copyProperties(e, targetClz))
.collect(Collectors.toList());
改为 Collectors.toList() 返回的是可变 ArrayList

1万+

被折叠的 条评论
为什么被折叠?



