@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
相关推荐
❀͜͡傀儡师1 分钟前
SpringBoot与Artemis整合,实现航空行李追踪消息中枢系统青云交2 分钟前
Java 大视界 -- Java 大数据在智能交通高速公路收费系统优化与通行效率提升实战Ulyanov3 分钟前
Impress.js深度技术解析:架构基础与结构化设计哪里不会点哪里.6 分钟前
IoC(控制反转)详解:Spring 的核心思想JiMoKuangXiangQu8 分钟前
Linux perf 子系统一览小宇的天下10 分钟前
Calibre :Standard Verification Rule Format(SVRF) Manual (1-1)充气大锤11 分钟前
前端实现流式输出配合katex.js麦兜*12 分钟前
SpringBoot Actuator监控端点详解,打造生产级应用健康检查滴水未满12 分钟前
uniapp的页面xj75730653316 分钟前
python中的序列化