@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
相关推荐
CoderYanger4 小时前
Java EE 进阶:8.MyBatis 操作数据库(入门)(第二弹)CQU_JIAKE6 小时前
11.7[高体】apcipot_rain7 小时前
C++转Java日记(04)红尘散仙7 小时前
谁说终端只能敲键盘?我用 Rust 给小说阅读器加上了鼠标特立独行的猫A8 小时前
我给女儿写了个打字练习:一边敲键盘,一边把小学英语单词记牢陈随易8 小时前
C++26 草案被否,二十八年来头一回ZhengEnCi9 小时前
Agent 工具怎么折叠海量输出才「爽」:Trae、Claude Code 的渐进式披露设计原理憧憬成为java架构高手的小白9 小时前
LangGraph4j 实战(下)天诰10 小时前
SA-K-11 检索会消失吗与四个未解问题2035去旅行11 小时前
bootcmd 详细讲解