@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
相关推荐
翼龙云_cloud几秒前
阿里云渠道商:轻量应用服务器连接常见问题与解决指南互联网哪些事情1 分钟前
服务器防御 SQL 注入小张程序人生5 分钟前
《系统掌握 ShardingSphere-JDBC:分库分表、读写分离、分布式事务一网打尽》小尧嵌入式5 分钟前
QT软件开发知识点流程及记事本开发爱宇阳5 分钟前
Linux 安全加固:设置命令行无操作超时退出呆萌小新@渊洁6 分钟前
声纹模型全流程实践-开发(训练 - 微调 - 部署 - 调用)carry杰9 分钟前
nacos bootstrap.yml 动态配置开发测试线上模式RisunJan10 分钟前
Linux命令-getenforce命令(快速检查 Linux 系统中 SELinux 的当前运行模式)SMF191911 分钟前
解决在 Linux 系统中,当你尝试以 root 用户登录时遇到 “Access denied“ 的错误翼龙云_cloud12 分钟前
亚马逊云渠道商:新手怎么利用AWS Lightsail部署 WordPress?