@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
相关推荐
-dcr几秒前
50.智能体好好研究1 分钟前
SpringBoot小案例打包执行流程代码游侠5 分钟前
学习笔记——ESP8266 WiFi模块Hello.Reader8 分钟前
PyFlink Configuration 一次讲透怎么配、配哪些、怎么“调得快且稳”行者9610 分钟前
Flutter跨平台开发适配OpenHarmony:进度条组件的深度实践__雨夜星辰__10 分钟前
VMware 17 下 Ubuntu 虚拟机与宿主机间复制粘贴失效问题云和数据.ChenGuang11 分钟前
Uvicorn 是 **Python 生态中用于运行异步 Web 应用的 ASGI 服务器**prettyxian12 分钟前
【linux】进程调度:优先级、时间片与O(1)算法IT_陈寒13 分钟前
SpringBoot 3.0实战:这5个新特性让你的开发效率提升50%rgeshfgreh13 分钟前
Spring Bean管理机制深度解析