@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);
}
SpringMVC下载
最新推荐文章于 2023-02-21 16:45:25 发布