首页 > 其他分享 >文件下载 同时响应状态码

文件下载 同时响应状态码

时间:2023-03-28 14:23:29浏览次数:31  
标签:文件 ResponseUtil RESPONSE 响应 result ResponseEntity response 下载

 

ResponseEntity 

文件下载 同时响应状态码 , 失败或者其它,响应 对应的message

    @GetMapping("/manifestReport")
    public ResponseEntity getManifestReportByBagIds(@RequestParam  List<String> bagIds, HttpServletRequest request, HttpServletResponse response) throws Exception{

        JSONObject result = lazadaManifestReportHandler.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);
        }

    }

 

标签:文件,ResponseUtil,RESPONSE,响应,result,ResponseEntity,response,下载
From: https://www.cnblogs.com/lshan/p/17265001.html

相关文章