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());
    }
相关推荐
❀͜͡傀儡师1 分钟前
SpringBoot与Artemis整合,实现航空行李追踪消息中枢系统
java·spring boot·后端
青云交2 分钟前
Java 大视界 -- Java 大数据在智能交通高速公路收费系统优化与通行效率提升实战
java
Ulyanov3 分钟前
Impress.js深度技术解析:架构基础与结构化设计
开发语言·前端·javascript
哪里不会点哪里.6 分钟前
IoC(控制反转)详解:Spring 的核心思想
java·spring·rpc
JiMoKuangXiangQu8 分钟前
Linux perf 子系统一览
linux·perf
小宇的天下10 分钟前
Calibre :Standard Verification Rule Format(SVRF) Manual (1-1)
大数据·前端·网络
充气大锤11 分钟前
前端实现流式输出配合katex.js
开发语言·前端·javascript·ai·vue
麦兜*12 分钟前
SpringBoot Actuator监控端点详解,打造生产级应用健康检查
java·spring boot·后端
滴水未满12 分钟前
uniapp的页面
前端·uni-app
xj75730653316 分钟前
python中的序列化
服务器·数据库·python