@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
相关推荐
meichaoWen1 分钟前
【nodejs】nodejs的一些基础知识@Autowire3 分钟前
Grid-grid-template-areas 属性kaico20183 分钟前
ConcurrentHashMap源码分析虫小宝5 分钟前
企业微信API接口对接中Java后端的模拟测试(Mock)与单元测试实战技巧Tim_Van7 分钟前
彻底解决:80 端口 GET/POST 正常,PUT 却报 ERR_CONNECTION_RESET?amazing-yuan8 分钟前
彻底解决该 TS 报错 + 提升编译效率乔冠宇9 分钟前
前端工程化——ESLint + Prettier 规范代码开发前端小白在前进9 分钟前
优雅的使用Nexent创建与部署前端面试智能体元媛媛10 分钟前
UiPath |5个基础自动化场景独自破碎E12 分钟前
Spring AI怎么实现结构化输出?