@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
相关推荐
小兵张健7 小时前
价值1000的 AI 工作流:Codex 通用前端协作模式sunny_7 小时前
面试踩大坑!同一段 Node.js 代码,CJS 和 ESM 的执行顺序居然是反的?!99% 的人都答错了拉不动的猪8 小时前
移动端调试工具VConsole初始化时的加载阻塞问题NE_STOP8 小时前
MyBatis-配置文件解读及MyBatis为何不用编写Mapper接口的实现类ayqy贾杰9 小时前
Agent First EngineeringIT_陈寒10 小时前
SpringBoot实战:5个让你的API性能翻倍的隐藏技巧iceiceiceice10 小时前
iOS PDF阅读器段评实现:如何从 PDFSelection 精准还原一个自然段大金乄10 小时前
封装一个vue2的elementUI 表格组件(包含表格编辑以及多级表头)葡萄城技术团队11 小时前
【性能优化篇】面对万行数据也不卡顿?揭秘协同服务器的“片段机制 (Fragments)”程序员阿峰11 小时前
2026前端必备:TensorFlow.js,浏览器里的AI引擎,不写Python也能玩转智能