保存文件ResponseEntity

@RequestMapping("testResponseEntityEntity")
 public ResponseEntity<byte[]> testResponseEntityEntity(HttpSession httpSession) throws IOException{
    byte[] body=null;
    ServletContext servletContext=httpSession.getServletContext();
    InputStream inputStream=servletContext.getResourceAsStream("/files/abc.txt");
    body=new byte[inputStream.available()];
    inputStream.read(body);
    //相应头
    HttpHeaders httpHeaders=new HttpHeaders();
    httpHeaders.add("Content-Disposition","attachment;filename=abc.txt");
   //相应码
    HttpStatus status=HttpStatus.OK;
    ResponseEntity<byte[]> responseEntity=new ResponseEntity<byte[]>(body,httpHeaders,status);
     return responseEntity;
 }
没搞明白呢

猜你喜欢

转载自blog.csdn.net/weixin_41050814/article/details/79557582
今日推荐