zoukankan      html  css  js  c++  java
  • 【SSM 下载】下载文件

    111111111

        /**
         * 导出客户数据
         */
        @RequestMapping("exportCustomer")
        public ResponseEntity<Object> exportCustomer(CustomerVo customerVo, HttpServletResponse response) {
            List<Customer> customers = customerService.queryAllCustomerForList(customerVo);
            String fileName = "客户数据.xls";
            String sheetName = "客户数据";
            org.apache.commons.io.output.ByteArrayOutputStream bos = ExprotCustomerUtils.exportCustomer(customers, sheetName);
    
            try {
                fileName = URLEncoder.encode(fileName, "UTF-8");//处理文件名乱码
                //创建封装响应头信息的对象
                HttpHeaders header = new HttpHeaders();
                //封装响应内容类型(APPLICATION_OCTET_STREAM 响应的内容不限定)
                header.setContentType(MediaType.APPLICATION_OCTET_STREAM);
                //设置下载的文件的名称
                header.setContentDispositionFormData("attachment", fileName);
                return new ResponseEntity<Object>(bos.toByteArray(), header, HttpStatus.CREATED);
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

    1111

        <!--POI excel导出-->
        <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>4.1.0</version>
        </dependency>
  • 相关阅读:
    介绍一种很好用的任务调度平台
    java中的进制与操作符
    类再生(合成、继承、final)
    初始化
    重新学习Spring2——IOC和AOP原理彻底搞懂
    重新学习Spring一--Spring在web项目中的启动过程
    JDK并发包
    java并行程序基础
    MVC模式
    访问者模式
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12257304.html
Copyright © 2011-2022 走看看