zoukankan      html  css  js  c++  java
  • Spring mvc下载文件java代码

    /**
         * 下载模板文件
         * @author cq
         */
            @RequestMapping("/downloadExcel.do")    
            public ResponseEntity<byte[]> download() throws IOException {    
                String path=servletContext.getRealPath("/")+"uploadFiles/file/purchase_modal.xls";  
                File file=new File(path);  
                HttpHeaders headers = new HttpHeaders();    
                String fileName=new String("批量导入模板.xls".getBytes("UTF-8"),"iso-8859-1");//为了解决中文名称乱码问题  
                headers.setContentDispositionFormData("attachment", fileName);   
                headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);   
                return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);    
            }
  • 相关阅读:
    JdbcTemplate
    Spring AOP——基于XML的进阶案例
    Spring
    面试题
    切面编程
    选择题
    Spring核心概念
    缓存
    BFC 神奇背后的原理
    git 教程
  • 原文地址:https://www.cnblogs.com/YangK-java/p/6652185.html
Copyright © 2011-2022 走看看