在controller中进行代码编写;

    @RequestMapping("/download")
    public ResponseEntity<byte[]> download(HttpServletRequest req)
            throws IOException {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        //解决中文名称乱码问题
        String filename = new String("你好.xls".getBytes("UTF-8"), "iso-8859-1");
        headers.setContentDispositionFormData("attachement", filename);
        String realpath = req.getSession().getServletContext()
                .getRealPath("/resources/upload/");
        String pathname = realpath + File.separator + "123";
        File file = new File(pathname);
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
                headers, HttpStatus.CREATED);
    }

 

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2018-05-16
  • 2021-10-14
  • 2021-04-03
  • 2021-06-10
  • 2021-11-28
猜你喜欢
  • 2017-12-21
  • 2021-12-28
  • 2021-12-10
  • 2021-05-18
  • 2021-07-04
  • 2021-09-24
  • 2022-12-23
相关资源
相似解决方案