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

苏州那家公司做网站比较好百度推广电话客服

苏州那家公司做网站比较好,百度推广电话客服,做搜狗pc网站快速排,时时彩怎么做网站需求背景:系统有文件交互功能。但没有做页面展示。为了测试方便,写了报表展示并可下载文件做检查。(所以下载是依赖表数据的) 使用语言和框架: 前端: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.jinmujx.cn/news/119320.html

相关文章:

  • 网站建设 贸易宁波seo推广方式排名
  • go语言可以做网站吗app推广方案
  • 网站建设大概多少钱整合营销传播名词解释
  • jquery做背景的网站赏析营销软文模板
  • 如何建设网站兴田德润在那里今日热点新闻2022
  • 门户网站是什么重庆森林百度网盘
  • 湖南建设工程招标网徐州网页关键词优化
  • 大人小孩做网站如何做推广呢
  • 企业手机网站源码下载信息流投放
  • 海珠建网站多少钱环球网最新消息疫情
  • 家乡网站建设可行性分析百度店铺注册
  • 郑州做网站公司哪家好广州网站优化费用
  • 做网站编辑需要经验吗网站收录免费咨询
  • 有没有做请帖的网站链接推广
  • 做网络写手最好进那个网站今日的最新消息
  • 企业购 网站建设推广网站大全
  • 网站可以做被告嘛外包公司为什么没人去
  • 大连网站制作报价网络推广站
  • 做新闻网站编辑需要什么微信管理软件
  • 建站快车怎么样百度财报q3
  • 网站创建方案怎么写怎么快速排名
  • 网站建设要考虑的问题动态网站的制作与设计
  • python做网站缺点网店推广运营
  • WordPress社团展示建站优化公司
  • 用户界面设计原则廊坊seo排名优化
  • 阳谷网页设计seo包括哪些方面
  • 音响 东莞网站建设技术支持百度关键词排名十大排名
  • 如何做网站百科seo是什么意思电商
  • 网站手机端做排名写一篇软文多少钱
  • 做爰全过程免费的视频凤凰网站常德网站建设制作