原理上讲就是返回的 ResponseEntity<byte[]> 形式的值就可以了
@RequestMapping("/api/watermark_download") public ResponseEntity<byte[]> returnWatermarkImage(HttpServletRequest request, HttpSession session) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); try { File file=new File("文件路径");byte[] test=FileUtils.readFileToByteArray(file); return new ResponseEntity<byte[]>(test, headers, HttpStatus.CREATED); } catch (Exception e) { e.printStackTrace(); } return new ResponseEntity<byte[]>(null, headers, HttpStatus.CREATED); }