下载导入模板

Posted xuchao0506

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了下载导入模板相关的知识,希望对你有一定的参考价值。

简单描述:需求要求做下载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下

技术分享图片

 



































以上是关于下载导入模板的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段1——vue主模板

VSCode自定义代码片段2——.vue文件的模板

VSCode自定义代码片段(vue主模板)

SpringBoot项目的创建:通过Spring官网提供的模板创建Spring boot项目,模板地址:https://start.spring.io/.(需联网,下载好模板后再导入到IDEA)

Eclipse 中的通用代码片段或模板