最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue+axios+java實(shí)現(xiàn)文件上傳功能

 更新時(shí)間:2022年06月23日 10:11:02   作者:鐵打的阿秀  
這篇文章主要為大家詳細(xì)介紹了vue+axios+java實(shí)現(xiàn)文件上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue+axios+java實(shí)現(xiàn)文件上傳的具體代碼,供大家參考,具體內(nèi)容如下

背景

vue.js + axios + element前端,Java后臺(tái)實(shí)現(xiàn)的文件上傳,簡(jiǎn)單例子

前端代碼

document.vue

<template>
? <div>
? ? <el-row class="action-row">
? ? ? <el-col :span="9">
? ? ? ? <el-button type="primary" icon="el-icon-plus" @click="add" size="medium">新增</el-button>
? ? ? </el-col>
? ? </el-row>
? ? <!-- 列表 -->
? ? <el-row>
? ? ? <el-table :data="docs" ref="docs" style="width: 100%" stripe @sort-change="sort" v-loading="loading">
? ? ? ? <el-table-column prop="docFileName" label="文件名稱" sortable align="center" min-width="10%"></el-table-column>
? ? ? ? <el-table-column prop="docFileType" label="文件類型" sortable align="center" min-width="10%"></el-table-column>
? ? ? ? <el-table-column prop="createTime" label="上傳時(shí)間" sortable align="center" min-width="10%"></el-table-column>
? ? ? </el-table>
? ? ? <div class="pagination">
? ? ? ? <el-pagination
? ? ? ? ? @size-change="handleSizeChange"
? ? ? ? ? @current-change="handlePageChange"
? ? ? ? ? :current-page="page"
? ? ? ? ? :page-size="limit"
? ? ? ? ? :total="total"
? ? ? ? ? :page-sizes="[10, 20, 50, 100]"
? ? ? ? ? layout="total, sizes, prev, pager, next, jumper"
? ? ? ? ? :background="true"
? ? ? ? ></el-pagination>
? ? ? </div>
? ? </el-row>
? ??
? ? <!-- 新建按鈕彈出框 -->
? ? <el-dialog title="上傳附件" :visible.sync="editvisible" :append-to-body="true" width="450px">
? ? ? <el-form :model="gtsDocument" :rules="rules" ref="gtsDocument" label-width="120px" label-position="left" size="small" class="edit-form">
? ? ? ? <el-form-item label="上傳附件" prop="file">
? ? ? ? ? <el-upload ref="upload" action="doUpload" :limit="limitNum" :auto-upload="false" :on-change="fileChange" :on-exceed="exceedFile" :file-list="fileList">
? ? ? ? ? ? <el-button size="small" plain>選擇文件</el-button>
? ? ? ? ? </el-upload>
? ? ? ? </el-form-item>
? ? ? </el-form>
? ? ? <div slot="footer" class="dialog-footer">
? ? ? ? <el-button @click="editvisible = false">取消</el-button>
? ? ? ? <el-button type="primary" @click="save">確定</el-button>
? ? ? </div>
? ? </el-dialog>
? </div>
</template>

<script>
import { list, del, create } from "@/api/gts/document";

export default {
? name: "GtsDocument",
? data() {
? ? return {
? ? ? editvisible: false, // 新增彈出框顯示標(biāo)識(shí):默認(rèn)不顯示
? ? ? gtsDocument: {
? ? ? ? // 隨附單據(jù)表單
? ? ? ? docType: "",
? ? ? ? docNo: "",
? ? ? ? gtsId: "",
? ? ? ? taskId: "",
? ? ? ? file: ""
? ? ? },
? ? ? isupdate: false,
? ? ? limitNum: 1,
? ? ? fileList: [],
? ? ? docs: [],
? ? ? loading: false,
? ? ? page: 1,
? ? ? limit: 10,
? ? ? total: 0,
? ? ? rules: {},
? ? };
? },
? created: function() {
? ? this.search();
? },
? methods: {
? ? search() {
? ? ? // 初始化列表?
? ? ? list(this.page, this.limit, this.$route.query.gtsId).then(v => {
? ? ? ? if ("ok" == v.data.msg) {
? ? ? ? ? this.docs = v.data.rows;
? ? ? ? ? this.total = v.data.total;
? ? ? ? }
? ? ? });
? ? },
? ? // 新增按鈕點(diǎn)擊事件
? ? add() {
? ? ? this.editvisible = true;
? ? ? this.$nextTick(() => {
? ? ? ? this.isupdate = false;
? ? ? ? this.$refs.gtsDocument.resetFields();
? ? ? });
? ? },
? ? // 文件超出個(gè)數(shù)限制時(shí)的校驗(yàn)
? ? exceedFile(files, fileList) {
? ? ? this.$notify.warning({
? ? ? ? title: this.$t("com.warning"),
? ? ? ? message: this.$t("com.onlySelect") + `${this.limitNum} ` + this.$t("com.someFile")
? ? ? });
? ? },
? ? // 文件狀態(tài)改變時(shí)的事件
? ? fileChange(file, fileList) {
? ? ? this.gtsDocument.file = file.raw;
? ? },
? ? // 保存
? ? save() {
? ? ? this.$refs["gtsDocument"].validate(valid => {
? ? ? ? if (valid) {
? ? ? ? ? let formData = new FormData();
? ? ? ? ? let file = this.gtsDocument.file;
? ? ? ? ? formData.append("file", file);
? ? ? ? ? if (!file) {
? ? ? ? ? ? return this.$message.warning('請(qǐng)選擇上傳附件');
? ? ? ? ? }
? ? ? ? ? create(formData).then(resp => {
? ? ? ? ? ? if ("ok" == resp.data.msg) {
? ? ? ? ? ? ? this.editvisible = false;
? ? ? ? ? ? ? this.$message.success('數(shù)據(jù)保存成功');
? ? ? ? ? ? ? this.search();
? ? ? ? ? ? ? this.$refs.upload.clearFiles();
? ? ? ? ? ? } else {
? ? ? ? ? ? ? this.$message.error('保存失敗');
? ? ? ? ? ? }
? ? ? ? ? });
? ? ? ? }
? ? ? });
? ? },
? ? handlePageChange(i) {
? ? ? this.page = i;
? ? ? this.search();
? ? },
? ? handleSizeChange(i) {
? ? ? this.limit = i;
? ? ? this.search();
? ? },
? }
};
</script>

<style rel="stylesheet/css">
.setting-form .el-form-item__label {
? padding-right: 30px;
}
</style>

document.js

import http from '@/utils/request'
import axios from 'axios'

export function create(formData) {
? return axios({
? ? url: 'http://localhost:8080/solvay-ecustoms//gts/documents/add',
? ? method: 'post',
? ? data: formData,
? ? withCredentials: true // cros with cookie
? })
}
export function list(page, limit, id) {
? return http.post('gts/documents', { page, limit, id })
}

后臺(tái)代碼

controller層

?/**
? ? ?* <p>Description: 附件上傳</p>
? ? ?* @param file ? ?上傳附件
? ? ?* @return
? ? ?*/
? ? @ResponseBody
? ? @PostMapping("/documents/add")
? ? public String addAttach(@RequestParam("file") MultipartFile file) throws IOException {
? ? ? ? // 獲取文件名稱
? ? ? ? String fileName = file.getOriginalFilename();
? ? ? ? if (StringUtils.isBlank(fileName)) {
? ? ? ? ? ? return jsonfailed("文件不能為空");
? ? ? ? }
? ? ? ? // 獲取文件的大小
? ? ? ? long fileSize = file.getSize();
? ? ? ? if (fileSize > 10 * 1024 * 1024) {
? ? ? ? ? ? return jsonfailed("上傳文件大小超出限定大小10M");
? ? ? ? }
? ? ? ? // 獲取文件的擴(kuò)展名
? ? ? ? // String extension = FilenameUtils.getExtension(fileName);
? ? ? ? // 獲取配置路徑
? ? ? ? String path = "D:/home/ecustoms/upload/";
? ? ? ? String newPath = path + UUID.randomUUID().toString().replaceAll("-", "") + "\\";
? ? ? ? File newDir = new File(newPath);
? ? ? ? if (!newDir.exists()) {
? ? ? ? ? ? newDir.mkdirs(); // 目錄不存在的情況下,創(chuàng)建目錄
? ? ? ? }
? ? ? ? File newFile = new File(newDir, fileName);
? ? ? ? //通過(guò)CommonsMultipartFile的方法直接寫文件(注意這個(gè)時(shí)候)
? ? ? ? file.transferTo(newFile);
? ? ? ? return "ok";
?}

實(shí)現(xiàn)截圖如下

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue-router判斷頁(yè)面未登錄自動(dòng)跳轉(zhuǎn)到登錄頁(yè)的方法示例

    vue-router判斷頁(yè)面未登錄自動(dòng)跳轉(zhuǎn)到登錄頁(yè)的方法示例

    這篇文章主要介紹了vue-router判斷頁(yè)面未登錄自動(dòng)跳轉(zhuǎn)到登錄頁(yè)的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • vue3關(guān)于時(shí)間顯示格式化的問(wèn)題

    vue3關(guān)于時(shí)間顯示格式化的問(wèn)題

    這篇文章主要介紹了vue3關(guān)于時(shí)間顯示格式化的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • Vite?Vue3?EsLint?Prettier配置步驟極簡(jiǎn)方法詳解

    Vite?Vue3?EsLint?Prettier配置步驟極簡(jiǎn)方法詳解

    這篇文章主要為大家介紹了Vite?Vue3?EsLint?Prettier配置步驟的極簡(jiǎn)方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • Vue前端整合Element?Ui的教程詳解

    Vue前端整合Element?Ui的教程詳解

    這篇文章主要介紹了Vue前端整合Element?Ui,本節(jié)內(nèi)容服務(wù)于SpringBoot?+?Vue?搭建?JavaWeb?增刪改查項(xiàng)目,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • vue路由傳參的基本實(shí)現(xiàn)方式小結(jié)【三種方式】

    vue路由傳參的基本實(shí)現(xiàn)方式小結(jié)【三種方式】

    這篇文章主要介紹了vue路由傳參的基本實(shí)現(xiàn)方式,結(jié)合實(shí)例形式總結(jié)分析了vue.js路由傳參的三種實(shí)現(xiàn)方式,包括params顯示傳參、不顯示參數(shù)以及query顯示參數(shù)傳參,需要的朋友可以參考下
    2020-02-02
  • vue.js實(shí)現(xiàn)開關(guān)(switch)組件實(shí)例代碼

    vue.js實(shí)現(xiàn)開關(guān)(switch)組件實(shí)例代碼

    這篇文章介紹了vue.js實(shí)現(xiàn)開關(guān)(switch)組件的實(shí)例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • Vue如何實(shí)現(xiàn)利用vuex永久儲(chǔ)存數(shù)據(jù)

    Vue如何實(shí)現(xiàn)利用vuex永久儲(chǔ)存數(shù)據(jù)

    這篇文章主要介紹了Vue如何實(shí)現(xiàn)利用vuex永久儲(chǔ)存數(shù)據(jù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Vue3按需引入Element?Plus以及定制主題色教程

    Vue3按需引入Element?Plus以及定制主題色教程

    由于涉及到vue框架單網(wǎng)頁(yè)應(yīng)用首屏加載慢這個(gè)問(wèn)題,我們需盡量減少加載負(fù)擔(dān),故采用按需引入的方式,只引入項(xiàng)目中用到的組件,這篇文章主要給大家介紹了關(guān)于Vue3按需引入Element?Plus以及定制主題色的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • 在Vue3中如何更優(yōu)雅的使用echart圖表詳解

    在Vue3中如何更優(yōu)雅的使用echart圖表詳解

    ECharts是一個(gè)強(qiáng)大的畫圖插件,在vue項(xiàng)目中,我們常常可以引用Echarts來(lái)完成完成一些圖表的操作,下面這篇文章主要給大家介紹了關(guān)于在Vue3中如何更優(yōu)雅的使用echart圖表的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • vue級(jí)聯(lián)選擇器的getCheckedNodes使用方式

    vue級(jí)聯(lián)選擇器的getCheckedNodes使用方式

    這篇文章主要介紹了vue級(jí)聯(lián)選擇器的getCheckedNodes使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04

最新評(píng)論

荔浦县| 陆丰市| 徐闻县| 广安市| 瓦房店市| 榕江县| 财经| 富锦市| 驻马店市| 荆州市| 黄山市| 汨罗市| 新郑市| 武夷山市| 合川市| 广饶县| 商丘市| 江都市| 清原| 怀来县| 玛纳斯县| 黄大仙区| 柳河县| 洞头县| 虎林市| 壶关县| 皮山县| 德阳市| 贺州市| 库车县| 色达县| 浦城县| 延津县| 鄱阳县| 图们市| 北京市| 永川市| 宁武县| 永仁县| 建始县| 依安县|