@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
相关推荐
Brookty2 分钟前
【JavaEE】线程安全-内存可见性、指令全排序獭.獭.12 分钟前
Linux -- 信号【上】智能化咨询13 分钟前
【Linux】【实战向】Linux 进程替换避坑指南:从理解 bash 阻塞等待,到亲手实现能执行 ls/cd 的 Shellhashiqimiya15 分钟前
centos配置环境变量jdkhashiqimiya16 分钟前
权限更改centos中系统文件无法创建文件夹,使用命令让普通用户具备操作文件夹Anson Jiang16 分钟前
浏览器标签页管理:使用chrome.tabs API实现新建、切换、抓取内容——Chrome插件开发从入门到精通系列教程06掘金安东尼19 分钟前
黑客劫持:周下载量超20+亿的NPM包被攻击tellmewhoisi20 分钟前
前置配置1:nacos 基本配置(注册与发现)会开花的二叉树25 分钟前
继承与组合:C++面向对象的核心剑亦未配妥1 小时前
移动端触摸事件与鼠标事件的触发机制详解