hutool导出CSV文件参考代码:
@PostMapping("/export")标签:rowList,Arrays,导出,hutool,add,new,CSV,csvWriter From: https://www.cnblogs.com/leeconblogs/p/18055102
public ResponseEntity<FileSystemResource> export() throws IOException {
// 写到临时目录,如果临时目录满了系统会自动清除。
File distFile = new File(System.getProperty("java.io.tmpdir"), "test.csv");
CsvWriter csvWriter = new CsvWriter(distFile);
csvWriter.writeHeaderLine("策略id", "账户id");
List<List<Long>> rowList = new ArrayList<>();
rowList.add(Arrays.asList(111L, 222L));
rowList.add(Arrays.asList(333L, 444L));
rowList.add(Arrays.asList(555L, 666L));
csvWriter.write(rowList);
csvWriter.close();
final FileSystemResource fsr = new FileSystemResource(distFile);
return ResponseEntity.status(HttpStatus.OK)
.header("Content-disposition", "attachment;filename=test.csv")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(fsr.contentLength())
.body(fsr);
}
如有问题请指出,THS!