vue2+vant2 多文件上传到spring boot 解决

@ApiOperation(value = "新增数据", response = Result.class)
    @DynamicParameters(name = "data", properties = {
    })
    @PostMapping(value = "/insert")
    public Result insert(MultipartFile[] fileList, String schoolName, String articleType, String body, Long createUserId) {

        confessWallService.insert(schoolName, fileList);
        return Result.ok();
    }
onSubmit() {
      if (this.articleType === null || this.articleType === '') {
        alert('选择发布类型');
        return;
      }
      //-- 创建新的数据对象 -->
      let formData = new FormData();
      //-- 将上传的文件放到数据对象中 -->
      this.fileList.forEach((file) =>{
        formData.append('fileList',file.file)
      })
      formData.append('schoolName', this.schoolName);
      confessWallAdd(formData).then((res) => {
        console.log(res.data)
        //var list = res.data.data.list;
      })
      //提交成功后
      this.$toast.success('文件上传成功');
      //this.fileList = []; // 清空文件列表
      //this.previewImages = []; // 清空预览图片数组
    },
  },

你可能感兴趣的:(java,前端,服务器)