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

江阴网站设计百姓网招聘信息

江阴网站设计,百姓网招聘信息,无锡网站制作工具,快推达seo图解: 前端设计: 前端设计一个link文字连接或者按钮(ElementUI)Element - The worlds most popular Vue UI framework 前端请求设计: import request from /utils/request //下载示例模型定义语言的JSON export const…

图解:

前端设计:

前端设计一个link文字连接或者按钮(ElementUI)Element - The world's most popular Vue UI framework

前端请求设计:

import request from '@/utils/request'
//下载示例模型定义语言的JSON
export const publishExportTemplateFile = (res, name, type = false) => {let url;if (type) {url = window.URL.createObjectURL(new Blob([res], {type: 'application/json5'}));//application后短语相应类型,// Important blob类型接收} else {url = window.URL.createObjectURL(new Blob([res]));}// const url = window.URL.createObjectURL(new Blob([res]));const link = document.createElement('a');link.style.display = 'none';link.href = url;link.setAttribute('download', name);document.body.appendChild(link);link.click();document.body.removeChild(link);
}export function downloadFile(filePath) {return request({url: '/configuration/download',method: 'get',params: { fileName: filePath, delete: false },responseType: 'blob' // 设置响应类型为 blob})
}

其中 publishExportTemplateFile 函数用于处理文件下载的前端逻辑,而 downloadFile 函数用于发起后端请求获取文件。

前端Vue组件

<template>
      <el-link type="primary" @click="download(filename)">下载示例配置文件</el-link>
</template>

<script>
import {downloadFile,publishExportTemplateFile } from "@/api/register/register";
export default {
  data() {
      return {
           filename:"template.json5"
      }
    },
methods(){
    download(filename){
      downloadFile(filename).then(response => {
        publishExportTemplateFile(response, filename);
      }).catch(error => {
        console.error('Download file failed:', error);
      });
    },
}
};
</script>

<style>

</style>

后端Controller:

@GetMapping("/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {try {if (!FileUtils.checkAllowDownload(fileName)) {throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 " , fileName));}String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);System.out.println("realFileName = " + realFileName);String filePath = RuoYiConfig.getDownloadPath() + fileName; //注意这里的路径要和你下载的路径对应response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);FileUtils.setAttachmentResponseHeader(response, realFileName);FileUtils.writeBytes(filePath, response.getOutputStream());if (delete) {FileUtils.deleteFile(filePath);}} catch (Exception e) {log.error("下载文件失败", e);}
}

后端Utils:

//从全局配置文件获取下载文件所在目录(src/main/java/com/ruoyi/common/config/RuoYiConfig.java)
@Component
@ConfigurationProperties(prefix = "ruoyi")
public class RuoYiConfig{public static String getProfile(){return profile;}public void setProfile(String profile){RuoYiConfig.profile = profile;}
/*** 获取下载路径*/public static String getDownloadPath(){return getProfile() + "/download/";}/** 上传路径 */private static String profile
//文件相关操作
public class FileUtils extends FileUtil {/*** 下载文件名重新编码** @param response     响应对象* @param realFileName 真实文件名*/public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException {String percentEncodedFileName = percentEncode(realFileName);StringBuilder contentDispositionValue = new StringBuilder();contentDispositionValue.append("attachment; filename=").append(percentEncodedFileName).append(";").append("filename*=").append("utf-8''").append(percentEncodedFileName);response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");response.setHeader("Content-disposition", contentDispositionValue.toString());response.setHeader("download-filename", percentEncodedFileName);}
public static void writeBytes(String filePath, OutputStream os) throws IOException
{FileInputStream fis = null;try{File file = new File(filePath);if (!file.exists()){throw new FileNotFoundException(filePath);}fis = new FileInputStream(file);byte[] b = new byte[1024];int length;while ((length = fis.read(b)) > 0){os.write(b, 0, length);}}catch (IOException e){throw e;}finally{IOUtils.close(os);IOUtils.close(fis);}
}

http://www.yayakq.cn/news/160339/

相关文章:

  • wordpress网站百度收录首页wordpress开发网上商城
  • 建行企业网站房地产网站设计方案
  • 北京网站建设报价明细wordpress 主题模板下载失败
  • 旅游微信网站建设在谷歌上做外贸网站有用吗
  • 湖南建设信誉查询网站一站式营销平台
  • 珠宝网站设计文案关闭小程序api
  • 如何制作网页网站关键词排名零芯互联关键词
  • 网站建设如何在宣传部备案贷款网站源码html
  • 搭建小网站网店装修论文
  • 北京网站建设 知乎网页个人主页
  • 做装修广告网站好网站运营工作的基本内容
  • 南京企业网站搭建西安网站建设优化
  • 东莞市 住房与城乡建设部网站dw做网站需要数据库么
  • 网站推广公司自媒体网站源码
  • 专业网站制作技术海报模板网站有哪些
  • 美食网站怎样做锅包肉网站建设费用IP
  • 禁止下载app网站wordpress怎么播放视频
  • 做网站哪个公司比较好宁波seo站外优化推广
  • 学院的网站怎么做广西网站建设路
  • 购物网站建设开发费用分析0建设营销型网站步骤
  • ic网站建设做百度网站好吗
  • 国外能下载模板的网站龙岩e龙岩网
  • 家具公司网站模板免费网页app一键生成软件
  • 电商网站开发计划深圳网站建设制作企业
  • 可信网站代码国外优秀的设计网站
  • 企业网站怎样做优化大岭山网站
  • 办公室装修专业网站2022世界500强企业排名
  • 买了vps后怎么安装Wordpress网站推广的优化
  • 开发网站合作协议登录百度账号注册
  • 网站规划管理系统辽宁住房和城乡建设部网站