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());
    }
相关推荐
恋猫de小郭1 天前
Flutter 设计包解耦新进展,material_ui 和 cupertino_ui 发布预告
android·前端·flutter
SakitamaX1 天前
LVS(Linux virual server)介绍与实验
linux·运维·lvs
小义_1 天前
【Docker】知识八
linux·docker·云原生
ShiJiuD6668889991 天前
Java stream流和方法引用
java·开发语言
linux_cfan1 天前
[2026深度评测] 打造“抖音级”丝滑体验:Web直播播放器选型与低延迟实践
前端·javascript·html5
开开心心_Every1 天前
CDR版本转换工具,支持多版本互转免升级软件
linux·运维·服务器·云原生·edge·pdf·serverless
天天向上的鹿茸1 天前
前端适配方案
前端·javascript
专注前端30年1 天前
【Java微服务架构】Spring Cloud Alibaba全家桶实战:Nacos+Sentinel+Seata+分布式事务
java·微服务·架构
We་ct1 天前
LeetCode 226. 翻转二叉树:两种解法(递归+迭代)详解
前端·算法·leetcode·链表·typescript
苏渡苇1 天前
轻量化AI落地:Java + Spring Boot 实现设备异常预判
java·人工智能·spring boot·后端·网络协议·tcp/ip·spring