@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
相关推荐
月屯2 分钟前
Pandoc 之--pdf-engine10km7 分钟前
java: HashMap.merge 的 Null 值陷阱:为什么 Stream API 会抛出 NPE晨星3349 分钟前
使用 IntelliJ IDEA 轻松连接 Java 与 MySQL 8 数据库睡觉早点10 分钟前
IntelliJ IDEA下载安装过程(含Java环境搭建)李少兄10 分钟前
IntelliJ IDEA Maven 工具栏消失怎么办?草酸艾司西酞普兰12 分钟前
idea中使用Qoder插件芽芽_012 分钟前
idea无法打开:Cannot collect JVM optionsFlying_Fish_roe13 分钟前
IntelliJ IDEA 2025 版本与其他历史版本的全面专业对比分析人在旅途我渐行渐远14 分钟前
idea 通过git撤销commit但未push的操作五道书童15 分钟前
IDEA中如何设置JVM启动参数