序
本文主要研究一下如何使用webflux提升数据导出效率
传统导出
@GetMapping("/download-old")
public ResponseEntity downloadInOldWays(){
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=demo.xls")
.header("Accept-Ranges", "bytes")
.body(new ByteArrayResource(exportBytes(1000)));
}
public byte[] exportBytes(int dataRow){
StringBuilder output = new StringBuilder();
output.append(ExcelUtil.startWorkbook());
output.append(ExcelUtil.startSheet());
output.append(ExcelUtil.startTable());
output.append(ExcelUtil.writeTitleRow(Sets.newHashSet("title","content")));
IntStream.rangeClosed(1,dataRow).forEach(i -> {
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {