@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
相关推荐
0x534 分钟前
网站通信(一)__zRainy__10 分钟前
Node.js Web 框架选型指南:从 Express 到 Hono 的全景对比Terra.K12 分钟前
Java异常学习[特殊字符]西瓜有点饿18 分钟前
PostCSS 和 UnoCSS 的作用和区别伟大的兔神1 小时前
我做了一个本地优先的 AI 图片工作台:Loomora v1.0.0 正式发布三言老师1 小时前
K8s集群运行时自动化运维全覆盖落地实操(下)葡萄城技术团队2 小时前
InfluxDB 2\.x 深度解析:核心架构、Flux 函数与制造业落地指南(三)Super 含2 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?counting money2 小时前
Java IO流详解:从InputStream到文件操作实战90后的晨仔2 小时前
uni-app项目 Vue3 状态管理 Pinia 完全指南:从概念到实战的深度解析