@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
相关推荐
bubusa~>_<8 分钟前
解决npm install 出现error,比如:ERR_SSL_CIPHER_OPERATION_FAILEDNerd Nirvana10 分钟前
OpenSSL crt & key (生成一套用于TLS双向认证的证书密钥)Allen Bright25 分钟前
【Java基础-46.3】Java泛型通配符详解:解锁类型安全的灵活编程柃歌29 分钟前
【UCB CS 61B SP24】Lecture 7 - Lists 4: Arrays and Lists学习笔记不修×蝙蝠33 分钟前
HTTP 协议(Ⅲ)柃歌38 分钟前
【UCB CS 61B SP24】Lecture 4 - Lists 2: SLLists学习笔记是姜姜啊!1 小时前
redis的应用,缓存,分布式锁流烟默1 小时前
vue和微信小程序处理markdown格式数据letisgo51 小时前
记录一次部署PC端网址全过程梨落秋溪、1 小时前
输入框元素覆盖冲突