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下

  • 相关阅读:
    Notification的使用
    Spring面向切面之AOP深入探讨
    使用注解配置Spring框架自动代理通知
    回顾Spring框架
    Spring利器之包扫描器
    Spring 核心概念以及入门教程
    Struts 2之动态方法调用,不会的赶紧来
    Struts2之过滤器和拦截器的区别
    Struts 2开讲了!!!
    Mybatis开篇以及配置教程
  • 原文地址:https://www.cnblogs.com/xuchao0506/p/9994699.html
Copyright © 2011-2022 走看看