@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
相关推荐
期待のcode39 分钟前
@RequestBody的伪表单提交场景栀秋6661 小时前
防抖 vs 节流:从百度搜索到京东电商,看前端性能优化的“节奏哲学”一颗烂土豆1 小时前
vfit.js v2.0.0 发布:精简、语义化与核心重构 🎉有意义1 小时前
深入防抖与节流:从闭包原理到性能优化实战SoveTingღ1 小时前
【问题解析】我的客户端与服务器交互无响应了?气π1 小时前
【JavaWeb】——(若依+AI)-帝可得实践项目zhougl9961 小时前
Vuex 模块命名冲突:问题解析与完整解决方案一世琉璃白_Y1 小时前
Ubuntu(VMware)虚拟机网络异常排查与解决方案可观测性用观测云1 小时前
网站/接口可用性拨测最佳实践