@RequestMapping("/testResponseEntity")
public ResponseEntity testResponseEntity(HttpSession session) throws IOException{
byte [] body = null;
ServletContext servletContext = session.getServletContext();
InputStream in = servletContext.getResourceAsStream("/files/abc.txt");
body = new byte[in.available()]; in.read(body); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Disposition", "attachment;filename=abc.txt"); HttpStatus statusCode = HttpStatus.OK; ResponseEntity response = new ResponseEntity(body, headers, statusCode); return response; }
转载于:https://www.cnblogs.com/znsongshu/p/10091814.html