@RequestMapping("/download")
public ResponseEntity<byte[]> download(HttpServletRequest request) throws IOException {
String realPath = request.getServletContext().getRealPath("/WEB-INF/image/{W@50[)]_~$50[SB9QC[J{D.jpg");
FileInputStream fileInputStream = new FileInputStream(realPath);
byte[] bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
HttpHeaders httpHeaders = new HttpHeaders();
String fileName = realPath.substring(realPath.lastIndexOf("\\") + 1);
httpHeaders.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, "utf-8"));
ResponseEntity<byte[]> responseEntity = new ResponseEntity<>(bytes, httpHeaders, HttpStatus.OK);
return responseEntity;
}
利用ResponseEntity