@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());
}
5分钟下载excel模板
被程序耽误的胡先生2025-02-22 8:25
相关推荐
恋猫de小郭1 天前
Flutter 设计包解耦新进展,material_ui 和 cupertino_ui 发布预告SakitamaX1 天前
LVS(Linux virual server)介绍与实验小义_1 天前
【Docker】知识八ShiJiuD6668889991 天前
Java stream流和方法引用linux_cfan1 天前
[2026深度评测] 打造“抖音级”丝滑体验:Web直播播放器选型与低延迟实践开开心心_Every1 天前
CDR版本转换工具,支持多版本互转免升级软件天天向上的鹿茸1 天前
前端适配方案专注前端30年1 天前
【Java微服务架构】Spring Cloud Alibaba全家桶实战:Nacos+Sentinel+Seata+分布式事务We་ct1 天前
LeetCode 226. 翻转二叉树:两种解法(递归+迭代)详解苏渡苇1 天前
轻量化AI落地:Java + Spring Boot 实现设备异常预判