导出源码
public void calcTCAllowanceByExcel(@PathVariable("organizationId") Long organizationId,@RequestParam(value = "file") @NotNull MultipartFile file,HttpServletResponse response) {OutputStream os = null;HSSFWorkbook workbook = null;try {String fileName = new SimpleDateFormat("yyMMddhhmmss").format(new Date()) + ".xls";response.setCharacterEncoding("UTF-8");response.setContentType("application/x-download;charset=utf-8");// 设置response内容的类型response.setContentType("application/x-download");// 定义输出类型response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("UTF-8"), "ISO8859-1"));workbook = cappCalcService.calcTCAllowanceByExcel(organizationId, file);os = response.getOutputStream();// 取得输出流workbook.write(os);} catch (IOException e) {throw new RuntimeException("导出excel异常!");} finally {if (os != null) {try {os.close();} catch (IOException e) {log.info("关闭流异常:" + e);}}}}
问题描述:
swagger执行后导出文件打开说格式异常或文件损坏:
postman执行后导出文件打开是正常的:
结论:
swagger服务的问题,和代码没有关系