图片演示
ftl层
<a href="download?filename=${src}">
<img src="${src}">
</a>
Controller层
// 文件下载
@GetMapping(value="/download")
public ResponseEntity<byte[]> download(HttpServletRequest request, @RequestParam("filename") String filename) throws Exception{
// 下载路径
File file = new File(path+File.separator+filename);
HttpHeaders headers = new HttpHeaders();
// 解决中文乱码
String downloadfile = new String(filename.getBytes("UTF-8"),"iso-8859-1");
// 以下载方式打开文件
headers.setContentDispositionFormData("attachment", downloadfile);
// 二进制流
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers,HttpStatus.CREATED);
}