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);
        }

    }

 

posted on 2023-03-28 14:18  lshan  阅读(55)  评论(0编辑  收藏  举报