ResponseEntity
文件下载 同时响应状态码 , 失败或者其它,响应 对应的message
@GetMapping("/myreport") public ResponseEntity getSeaReportByBagIds(@RequestParam List<String> bagIds, HttpServletRequest request, HttpServletResponse response) throws Exception{ JSONObject result = SeaReportHandler.getManifestReportByBagIds(bagIds); if((ResponseCode.SUCCESS.getCode()+"").equalsIgnoreCase(result.getString(ResponseUtil.RESPONSE_CODE))){ XSSFWorkbook workbook = (XSSFWorkbook)result.get(ResponseUtil.RESPONSE_DATA); OutputStream output=response.getOutputStream(); response.reset(); String fileName="Sea_Report" + DateUtils.formatDate(new Date(),DateUtils.STANDARD_NO_BLANK); response.setHeader("Content-disposition", "attachment; filename="+fileName+".xlsx"); response.setContentType("application/msexcel"); workbook.write(output); return ResponseEntity.status(200).body(""); }else { return ResponseEntity.status(Integer.valueOf(result.getString(ResponseUtil.RESPONSE_CODE))).body(result); } }