SpringMVC下载

来源:互联网 发布:数据存储解决方案 编辑:程序博客网 时间:2024/05/18 00:50
    @RequestMapping("/downloadTest")    public ResponseEntity<byte[]> export(String filePath, String fileName) throws IOException {          if (fileName == null){            fileName = filePath.substring(filePath.lastIndexOf('\\') + 1);        }        HttpHeaders headers = new HttpHeaders();            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);            headers.setContentDispositionFormData("attachment", fileName);            return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(new File(filePath)),                                                  headers, HttpStatus.CREATED);        }