当前位置: 首页 > news >正文

通过blob请求后端导出文件

后端controller

 @PostMapping("/exportPlanProject2")public void exportActive(@RequestBody IfPlanListDTO plan, HttpServletResponse httpServletResponse) throws IOException {}

后端service

    public void exportExcel2(HttpServletResponse response) throws IOException {OutputStream out = response.getOutputStream();try {response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.setCharacterEncoding(Charsets.UTF_8.name());String fileName = "首页导出";fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");wb.write(out);} catch (Exception e) {log.error("导出Excel异常{}", e.getMessage());throw new CustomException("导出Excel失败,请联系网站管理员!");} finally {if (wb != null) {try {wb.close();} catch (IOException e1) {e1.printStackTrace();}}if (out != null) {try {out.close();} catch (IOException e1) {e1.printStackTrace();}}}}

前端

     request({method: 'post',url: '/investment/plan/remake/exportPlanProject2',data: this.queryParams,responseType: 'blob'}).then(res => {console.log('res---',res)const aLink = document.createElement('a')var fileName = '文件名称' + moment().format('YYYYMMDDHHmmss') + '.xlsx'fileName = fileName.replace(/\"/g, '')const url = window.URL.createObjectURL(res)console.log('url---',url)aLink.href = urlaLink.download = fileNameaLink.click()aLink.remove()URL.revokeObjectURL(url)})
http://www.lryc.cn/news/513992.html

相关文章:

  • 养老院小程序怎么搭建?让老年人老有所养,老有所依!
  • 【2024美国数学建模AB题原文翻译】
  • 判断旗帜是否符合ISO新标准
  • 海量数据存储实现方案设计1-mycat版
  • Elasticsearch检索之三:官方推荐方案search_after检索实现(golang)
  • hot100_238. 除自身以外数组的乘积
  • 软件测试基础详解
  • MySQL 备份方案设计之准备事项
  • 《计算机网络A》单选题-复习题库解析-最终
  • 向 SwiftUI 视图注入 managedObjectContext 环境变量导致 Xcode 预览(Preview)崩溃的解决
  • Ruby 数据类型
  • 复合机器人正以其高效、精准、灵活的特点,逐渐在汽车装配线上崭露头角
  • Docker + JMeter + InfluxDB + Grafana搭建压测可视化实时监控
  • leetcode 2658. 网格图中鱼的最大数目
  • Java 集合 Collection、List、Set
  • 报错:nginx [emerg] open() etcnginxnginx.conf failed (2 No such file or directory)
  • 基于AI的运维资源调度:效率与智能的双重提升
  • 自动化办公 | 根据成绩进行自动评级
  • 纯血鸿蒙ArkUI线性布局详解
  • 小程序组件 —— 22 组件案例 - 轮播区域绘制
  • 如何判断一个学术论文是否具有真正的科研价值?ChatGPT如何提供帮助?
  • 【置顶】测试学习笔记整理
  • 新浪微博Java开发面试题及参考答案
  • 【SQL Server】教材数据库(1)
  • Windows系统下载、部署Node.js与npm环境的方法
  • SQL 总结
  • 设计一个基于Spring Boot开发的电商网站,部署在阿里云上
  • Java jni调用nnom rnn-denoise 降噪
  • C++软件设计模式之状态模式
  • Microsoft Visual Studio中的/MT, /MTd,/MD,/MDd分别是什么意思?