controller代码:
@PostMapping("/exportAllBank/{contracts}") @PreAuthorize("hasAuthority('contract:exportAllBank')" public ResponseResult exportAllBank(@PathVariable("contracts") List<Integer> contracts){ //获取转换后的list List<ContractDto> contractDtoList = contractService.selectAllBank(contracts); //如果目录不存在,创建目录 execlServer.createDirectory(Constants.excelDirectory); //导出文件的存放路径及名字 String fileName = Constants.excelDirectory+ System.currentTimeMillis()+"contract.xlsx"; EasyExcel.write(fileName,ContractDto.class) .sheet("业务信息") .doWrite(contractDtoList); return ResponseResult.succ("导出成功:"+fileName); }
test代码:
@Test @WithMockUser(authorities = "contract:exportAllBank") void exportAllBank() throws Exception { List<Integer> contracts = new ArrayList<>(); List<