zoukankan      html  css  js  c++  java
  • 下载导入模板

    简单描述:需求要求做下载Excel模板,在模板上填充数据,然后在做导入功能。

    //html代码
    <div class="btn-group">
    <button class="btn sbold green" id="submitRelease" onclick="downloadTemplate();">
       <span class="ladda-label">下载模板</span>
    </button>
    </div> 

    //js代码
    function downloadTemplate() {
    window.location.href = rootPath + "/vrxx/abc/downloadTemplate"
    } 
    //后台java代码
    @ResponseBody
    @RequestMapping("/downloadTemplate")
    public void downloadTemplate(HttpServletResponse response, HttpSession session) {
    try {
    InputStream inputStream = (InputStream) this.getClass().getClassLoader().getResourceAsStream("excelexport/rights.xlsx");
    response.setContentType("application/zip");
    OutputStream out = response.getOutputStream();
    response.setHeader("Content-Disposition", "attachment; filename=" + "base" + ".xlsx");
    int b = 0;
    byte[] buffer = new byte[1000000];
    while (b != -1) {
    b = inputStream.read(buffer);
    if (b != -1) out.write(buffer, 0, b);
    }
    inputStream.close();
    out.close();
    out.flush();
    } catch (IOException e) {
    e.printStackTrace();
    logger.error("模板下载失败");
    }
    }

     说明:首先,括号里的参数session,没有用到,可以去掉。

        其次,excelexport/rights.xlsx这个模板excel文件是存放在项目根目录的resources下

  • 相关阅读:
    Thread中的join使用
    java.lang.NoClassDefFoundError: Ljavax/enterprise/inject/spi/BeanManager;
    org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xm
    maven 中使用jstl 错误解决
    eclipse 安装maven
    前端 JS事件操作
    前端 JS
    前端 固定位置 与绝对定位
    前端 显示与隐藏
    前端 盒子阴影
  • 原文地址:https://www.cnblogs.com/xuchao0506/p/9994699.html
Copyright © 2011-2022 走看看