当前位置: 首页> 教育> 高考 > 成都网站开发培训机构_多少钱算有钱_武汉网络关键词排名_上海排名优化seobwyseo

成都网站开发培训机构_多少钱算有钱_武汉网络关键词排名_上海排名优化seobwyseo

时间:2025/7/11 18:30:21来源:https://blog.csdn.net/weixin_48616345/article/details/145614266 浏览次数:0次
成都网站开发培训机构_多少钱算有钱_武汉网络关键词排名_上海排名优化seobwyseo

springboot+vue 下载文件中文乱码

springboot

                        HttpHeaders responseHeaders = new HttpHeaders();String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");responseHeaders.set("Content-Disposition","attachment; filename=\"" + encodedFileName + "\"; filename*=UTF-8''" + encodedFileName);return new ResponseEntity<>(EntityUtils.toByteArray(entity), responseHeaders, HttpStatus.SC_OK);

vue

    downloadFile(row) {downloadOX({fileId: row.id}).then(response => {const contentDisposition = response.headers['content-disposition'];let filename = "default_filename.ext"; // 默认文件名,确保有扩展名if (contentDisposition) {const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition);if (matches!= null && matches[1]) {filename = decodeURIComponent(matches[1].replace(/['"]/g, ''));}}// 创建一个隐藏的<a>元素用于触发浏览器下载const url = window.URL.createObjectURL(new Blob([response.data]));const link = document.createElement('a');link.href = url;link.setAttribute("download", filename);// 将<a>元素添加到DOM中document.body.appendChild(link);// 触发点击事件link.click();// 下载完成后移除<a>元素link.remove();window.URL.revokeObjectURL(url);this.$message.success("文件下载成功");}).catch(error => {this.$message.error("文件下载失败:" + (error || '未知错误'));});},
关键字:成都网站开发培训机构_多少钱算有钱_武汉网络关键词排名_上海排名优化seobwyseo

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: