1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 前后端分离的文件上传 上传zip或者rar压缩包(vue+springboot)。

前后端分离的文件上传 上传zip或者rar压缩包(vue+springboot)。

时间:2022-08-29 09:06:25

相关推荐

前后端分离的文件上传 上传zip或者rar压缩包(vue+springboot)。

使用axios做前端的请求,对请求函数进行封装,并暴露出来。返回的值是一个promise对象,前端使用异步函数async,await进行解析。

export function ajaxFile(url, data) {return new Promise(function (resolve, reject) {// 执行异步ajax请求let promise// 发送post请求//data = QS.stringify(data)//console.log("ajaxFile")promise = axios.post(url, data)promise.then(function (response) {// 成功了调用resolve()//console.log(response.data);resolve(response.data) //返回 response的data}).catch(function (error) {//失败了调用reject()console.log(error);reject(error)})})}

进行接口封装,

//文件上传export const fileUpload = (params) => ajaxFile(BASE_URL_F + REQUEST_FILEUPLOAD, params)

前端页面

<div v-loading="loading" element-loading-text="加载时间过长,请等待。。。"><div ><input type="file" ref="up_file" accept=".zip, .rar" style="width: auto"><el-button type="primary" v-if="uploadShow" @click="upload">上传<i class="el-icon-upload el-icon--right"></i></el-button></div><el-dialog title="提示":visible.sync="dialogVisible1"width="30%"><span>确定上传文件吗?原有文件将被删除!</span><span slot="footer" class="dialog-footer"><el-button type="primary" @click="dialogVisible1 = false">取 消</el-button><el-button @click="uploadCertain">确 定</el-button></span></el-dialog>

js代码

data() {dialogVisible1:false,loading:false,//加载}//导入EXCELmethods: {async upload(){if(this.$refs.up_file.files[0] === undefined){// this.dialogVisible2 = truethis.noSelectedFile_message()return}this.dialogVisible1 = true},async uploadCertain(){this.dialogVisible1=falsethis.loading = true;var formData = new FormData()formData.append("file",this.$refs.up_file.files[0])var _this = this;const res = await fileUpload(formData).catch(function (err) {_this.loading = false;alert(111)})this.loading = false;switch (res) {case "error":_this.$message.error("文件导入失败,请联系相关人员!");break;default:if(res instanceof Array){await this.loadItem1();if(res.length==0){_this.$message.success("文件导入成功");}else {_this.$message.warning("存在部分文件导入失败");res.forEach((value => console.log(value)));}}}},noSelectedFile_message(){this.$message.warning('请选择文件')}}

一般文件保存需要使用时间作为文件的标识。

使用 SimpleDateFormat来创建自己想要的格式。SimpleDateFormat是DateFormat的一个具体类,它允许我们指定格式模式从而获取我们理想的格式化日期和时间。通过SimpleDateFormat的构造方法你可以传入一个格式模式字符串例如:

Date date = new Date();SimpleDateFormat format = new SimpleDateFormat("今天是yyyy-MM-dd E hh:mm:ss,是yyyy年的第DD天,在该月是第dd天");System.out.println(format.format(date));将会输出:今天是-12-10 星期四 09:38:16,是的第344天,在该月是第10天

后端代码

写不下去了太多了,(哭)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。