5分钟下载excel模板

复制代码
@PostMapping("/downloadTemplate")
@Operation(summary="下载入职excel模板")
public void downloadExcel(HttpServletResponse response){
    try{
        //获取输入流,原始模板位置
        String filePath = "template/gridPersonTemplate.xlsx";
        ClassPathResource resource = new ClassPathResource(filePath);
        InputStream bis = resource.getInputStream();
        //假如以中文名下载的话,设置下载文件名称
        String filename = "gridPersonTemplate1.xlsx";
        //转码,免得文件名中文乱码
        filename = URLEncoder.encode(filename,"UTF-8");
        //设置文件下载头
        response.addHeader("Content-Disposition", "attachment;filename=" + filename);
        //1.设置文件ContentType类型,这样设置,会自动判断下载文件类型
        response.setContentType("multipart/form-data");
        BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
        int len = 0;
        while((len = bis.read()) != -1){
            out.write(len);
            out.flush();
        }
        out.close();
    }catch (Exception e){
        log.error(e.getMessage());
    }
相关推荐
码农水水10 分钟前
SpringBoot配置优化:Tomcat+数据库+缓存+日志全场景教程
java·数据库·spring boot·后端·算法·tomcat·哈希算法
毕设源码-朱学姐10 分钟前
【开题答辩全过程】以 基于ssm的电影推荐与分享平台的设计与实现为例,包含答辩的问题和答案
java
Wpa.wk11 分钟前
Docker- 故障注入(混沌工程)测试(简单过程阐述)
linux·运维·分布式·测试工具·docker·容器
江湖有缘11 分钟前
Docker部署NextTrace Web路由工具
前端·docker·容器
独自破碎E13 分钟前
LCR004-只出现一次的数字II
java·开发语言
Elias不吃糖17 分钟前
Spring Bean 注入与容器管理:从“怎么交给容器”到“怎么被注入使用”的完整总结
java·spring·rpc·bean
iFlow_AI19 分钟前
将iFlow CLI装进u盘,即插即用
linux·编辑器·vim·ai编程·u盘·iflow·iflow cli
Chan1625 分钟前
《Redis设计与实现》| 常用数据类型与AOF、RDB持久化
java·开发语言·redis·spring·面试·java-ee
wljt26 分钟前
游标分页原理
java·前端·数据库
weixin_4569074134 分钟前
【html+Tss 故障排查】链20230304 最详细解析之像素已拉取,容器仍起不来(含命令清单)
前端·html