【SSM 下载】下载文件

111111111

    /**
     * 导出客户数据
     */
    @RequestMapping("exportCustomer")
    public ResponseEntity exportCustomer(CustomerVo customerVo, HttpServletResponse response) {
        List 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(bos.toByteArray(), header, HttpStatus.CREATED);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    } 
  
 

1111

    
    <dependency>
      <groupId>org.apache.poigroupId>
      <artifactId>poiartifactId>
      <version>4.1.0version>
    dependency>

 

你可能感兴趣的:(【SSM 下载】下载文件)