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

苏州那家公司做网站比较好今日新闻事件

苏州那家公司做网站比较好,今日新闻事件,国内最新新闻摘抄2023年,网站因该怎么做参考文献需求背景:系统有文件交互功能。但没有做页面展示。为了测试方便,写了报表展示并可下载文件做检查。(所以下载是依赖表数据的) 使用语言和框架: 前端:vue-cli 后端:springBoot 前端实现 1、在报表vue文件,显示下载按钮并实现下载接口请求和处理。 //报…

需求背景:系统有文件交互功能。但没有做页面展示。为了测试方便,写了报表展示并可下载文件做检查。(所以下载是依赖表数据的)

使用语言和框架:
前端:vue-cli 后端:springBoot

前端实现
1、在报表vue文件,显示下载按钮并实现下载接口请求和处理。

//报表操作栏添加下载按招
//  slot-scope="{ row, $index ) -- 绑定行数据
// downloadFile(row, $index)"-- 调下载方法,入参行数据
// v-if="'0, 1, 2, 6+ 7 . indexOf(row.FILE_STATUS)>= 0” -- 指定文件状态才显示下载按钮 
<el-table-colum label="操作”width="120" fixed="right" align="center">
<template slot-scope="{ row, $index }"
<el-button v-if="2,3,5,9 '.indexOf(row. FILE_STATUS) >= 0" type="primary" size="mini" @c1ick="downloadFile(row, $index)>下载</el-button>
<el-button> v-if="'0, 1; 2, 6, 7'. indexOf(row.FILE_STATUS) >= 0" type-"primary" size="mini" @click="openUploadFileDielog(row,$index)">上传</el-button>
</template)
</el-table-column>
// js脚本
<script>
//导入需要用到的api
import { getReportList,downloadFile } from '@/api/report'// method 增加下载方法
//文件下载
downloadFile(row){ 
const params ={
fileType : encodeURIComponent(row.FILE_TYPE ), 
fileDir : encodeURIComponent(row.FILE_DIR), 
id:row.ID}
downloadFile(params).then(res ->{ 
console.log("下载的文件流”,res)
const link=document.createElement('a'); 
try{
let blob =res.data //如果后台返回的直接是b1ob对象类型,直接获取数据
console.log(JSON.stringify(res.headers ))
let _fileName = res.headers['content-disposition' ].split('; ')[1].split('=')[1];//拆解读取文件名
link.style.display='none';
const url = window.URL || window.webkitURL || window.moxURL;
link.href=window.URL.createObjectURL(new Blob([blob],(type:'application/txt'}));
link.download =_fileName; //下载的文件名称
link.click();
window.URL.revokeObjectURL(ur1);
}catch (e){
console.log('下载的文件出错',e)
}
})
}
</script>

2、接口管理页面,新增下载接口
\项目路径\src\api\report.js

// 下载接口
export function downloadFile(data) {
return request({
url: '/downloadFile', 
method: 'post', 
timeout: 90000,
responseType: 'blob', 
data
})
}

后端实现
1、controller新增接口

@RequestMapping(value ={"/{env}/downloadFile"})
public vaid downloadFile(@PathVariable String env, @valid FileDTO fileDTO,HttpServletRequest httpRequest,HttpServletResponse response) throws IOException {
xxServiceImpl.downloadFi1e(env,response,fileDTO);

xxServiceImpl = service类名

2、service层实现下载功能

public void downloadFile(String env, HttpServletResponse response,FileDTO fileDTO) throws BizException, IOException {
System,out.println("downloadFile fileDTO =" + fileDTO);
// 本来是需要通过fileDTO来获取文件路径的,省略,假设文件路径在./filePath/fileName.XX  
//服务器文件路径,仅当下载服务跟文件在同一个服务器时可行。如果文件在其他服务器,需要开通ssh访问权限后,通过 sshConnect来获取文件。
String localPath ="./filePath/fileName.XX"; 
String os = System.getProperty("os.name").toLowerCase();
// 方便本地调式下载功能
if (os.contains("windows")){
localPath = "D:\localPath\fileName.xx"; 
}
OutputStream out= null; 
InputStream is= null;
try{
File file = new File(localPath);
//包装错误信息
if (!file.exists()){
System.out.println("文件不存在"+ localPath); 
JSONObject res = new JSONObject();
String err = localPath +”文件不存在"; 
res.put("desc",err);
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.getOutputStream().write(res.toString().getBytes("UTF-8")); 
return;
}
String fileName =file.getName();
fileName = new String(fileName.getBytes("UTF-8"),"iso8859-1"); 
System.out.println("fileName="+ fileName);
//防止前端找不到 content-disposition
response.setHeader("Access-Control-Expose-Headers", "content-disposition"); 
response.setHeader("content-disposition","attachment;filename="+ fileName);
response.setContentType("application/x-download"); 
response,setCharacterEncoding("GBK"); 
response.addHeader("Pargam","no-cache");
response,addHeader("Cache-Control", "no-cache"); 
response.flushBuffer();
//获取文件流
is = new FileInputStream(fu11Fi1eNamePath); 
int len =0;
byte[] b = new byte[1024];
out = response.getOutputStream(); 
while ((len = is.read(b)) != -1){
//将缓冲区数据输出到浏览器 
out.write(b,0, len);
}
out.flush( );
} catch (Exception e) {
System.out .println("e.getMessage() = " + e.getMessage());
} finally {
try{
if (null != out) {
out.close();
}
if (null != is) {
is.close();
} catch (Exception e){
System.out.println("e = " + e.getMessage());
}}}

ps: 依赖包都是框架有的,爆红的位置按键alt+enter,按提示导入即可。

http://www.ds6.com.cn/news/20506.html

相关文章:

  • 现在网站如何做优化发布外链的平台有哪些
  • 使用中文域名的网站我想开个网站平台怎么开呢
  • 怎样建设个人游戏网站新媒体营销策略
  • 做网站建设的可以发广告的平台
  • 编程和做网站有关系吗提高关键词排名的软文案例
  • 重庆江北营销型网站建设价格附近学电脑培训班
  • WordPress的cookieseo网站的优化方案
  • 天津市住房与建设管理委员会网站优化营商环境 助推高质量发展
  • 福州哪家企业网站建设设计最高端贵港seo
  • 企业网站建设需要哪些费用网络广告案例
  • wordpress联系我们优化营商环境心得体会个人
  • 做网站可以用ai做网站seo诊断分析和优化方案
  • 太原做淘宝网站的网站收录怎么做
  • 触摸屏互动网站建设案例电商推广
  • 北沙滩网站建设公司网络营销策略分析案例
  • 织梦响应式网站整站seo排名要多少钱
  • excel服务器做网站南宁seo团队哪家好
  • 建筑资质最新政策2023年win7优化工具
  • 手机网站信任从哪里设置四种营销策略
  • 平面设计接单价格seo推广排名平台有哪些
  • iis 网站文件被占用360站长平台
  • 网站建设 海口网站优化团队
  • 邯郸企业做网站报价保定seo建站
  • 做网站必须学php吗百度大数据分析工具
  • 中国建设银行wap网站seo哪家强
  • 建设b2b网站要求电子商务网站建设方案
  • 北京公司网站建设定天津网站优化
  • 网站建设vipjiuseluseo分析报告怎么写
  • it前端和后端的区别湖南企业seo优化推荐
  • 网站开发最重要的技巧木卢seo教程