• 下载excel模板


    /*
    * 下载客户档案模板
    * @param response
    */
    @ApiOperation(value = "下载客户档案模板", notes = "下载客户档案模板")
    @PostMapping(value = "/downloadCustomerTemplate")
    public void downloadCustomerTemplate(HttpServletResponse response) {
    fis = null;
    try {
    String filePath = "C:/test/customer_excel_imp.xls";
    File file = new File(filePath);
    if (!file.exists()) {
    response.sendError(404, "File not found!");
    } else {
    // 取得文件名。
    String filename = file.getName();
    // 以流的形式下载文件。
    fis = new BufferedInputStream(new FileInputStream(filePath));
    byte[] buffer = new byte[fis.available()];
    // 清空response
    fis.read(buffer);
    // JSONP 解决跨域问题
    response.reset();
    response.addHeader("Access-Control-Allow-Origin", "*");
    response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
    response.addHeader("Access-Control-Allow-Headers", "Content-Type");
    // 设置response的Header
    response.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"iso-8859-1"));
    response.addHeader("Content-Length", "" + file.length());
    OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
    response.setContentType("application/octet-stream");
    toClient.write(buffer);
    toClient.flush();
    toClient.close();
    fis.close();
    }
    } catch (IOException ex) {
    logger.error("异常:",ex.getMessage());
    }
    }
  • 相关阅读:
    C++ | Int转十六进制字符串
    Qt | QML Image SSL handshake failed
    《大话数据结构》第一章 数据结构绪论
    8组Beta冲刺4/5
    8组Beta冲刺1/5
    8组Beta冲刺3/5
    8组Beta冲刺2/5
    8组Beta冲刺5/5
    软工实践个人总结
    8组Beta冲刺总结
  • 原文地址:https://www.cnblogs.com/pan-my/p/11052899.html
Copyright © 2020-2023  润新知