@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
相关推荐
未知原色几秒前
NODE.JSB快速下载及安装⑩-2 分钟前
JVM-内存模型小年糕是糕手3 分钟前
【C++】内存管理(上)222you4 分钟前
vue目录文件夹的作用wanhengidc5 分钟前
云手机大规模出现的趋势 巨 椰月屯5 分钟前
pandoc安装与使用(html、makdown转docx、pdf)kyle~5 分钟前
Linux---scp 安全文件传输Qiuner5 分钟前
Spring Boot 机制五: Bean 生命周期与后置处理器(BeanPostProcessor)源码深度剖析路边草随风6 分钟前
java实现发布flink yarn session模式作业qq_12498707538 分钟前
基于Spring Boot的阳光餐盘点餐系统(源码+论文+部署+安装)