public Mono<ServerResponse> test(ServerRequest request) throws Exception {
File excel = new File("tmp");
var out = new FileOutputStream(excel);
var writer = new ExcelWriter(out, ExcelTypeEnum.XLSX,false);
Sheet sheet1 = new Sheet(1, 0);
sheet1.setSheetName("第一个sheet");
writer.write(Arrays.asList(), sheet1);
writer.finish();
return ServerResponse.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=test.xlsx")
.contentType(new MediaType("multipart/form-data"))
.body((p, a) -> {
var resp = (ZeroCopyHttpOutputMessage) p;
return resp.writeWith(excel, 0, excel.length());
}).doFinally(a -> {excel.deleteOnExit();});
}
webflux RouterFunction方式下载文件demo
最新推荐文章于 2024-05-24 09:14:00 发布