ResponseEntity下载

代码

@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;
	}
	

你可能感兴趣的:(上传与下载)