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

转载于:https://www.cnblogs.com/znsongshu/p/10091814.html

你可能感兴趣的:(responseEntity 实现文件下载)