Java后端接收 POST
@ApiOperation(value = "添加测试报告信息", notes = "添加测试报告信息")
@EnableAuth
@PostMapping(value = "/saveTestReport")
@Transactional(rollbackFor = Exception.class)
public ResultData saveTestReport(@RequestParam(value = "files") List<MultipartFile> files,
TestReport testReport) {
前端核心代码:
<el-col :span="24">
<el-form-item label="上传文件 :">
<template slot-scope="scope">
<el-upload ref="MultipartFile1"
style="display: inline"
v-show="dialogInfo.type==='2'"
action=""
:file-list="fileList"
list-type="picture-card"
accept="image/*"
:disabled="isDisabled"
:auto-upload="false"
multiple
:before-upload="beforeUpload"
:on-exceed="onExceed"
:on-error="onError"
>
<i class="el-icon-plus"></i>
</el-upload>
<el-upload ref="MultipartFile"
class="upload-demo"
v-show="dialogInfo.type==='1'"
action=""
:file-list="fileList1"
accept=".pdf"
:auto-upload="false"
:disabled="isDisabled"
multiple
:before-upload="beforeUploadPdf"
:on-exceed="onExceedPdf"
:on-error="onErrorPdf"
>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传pdf文件</div>
</el-upload>
</template>
</el-form-item>
</el-col>
fillFormData(){
let formData = new FormData();
let MultipartFiles;
if (this.dialogInfo.type==='1'){//pdf
MultipartFiles = this.$refs['MultipartFile'].uploadFiles;//文件
}else{//图片
MultipartFiles = this.$refs['MultipartFile1'].uploadFiles;//文件
}
if(MultipartFiles===undefined){
this.$message.error("请上传文件");
return false;
}
this.dialogInfo.unitName=this.selectValHome1
for(let key in this.dialogInfo){
formData.append(key, this.dialogInfo[key]);
}
for(let i=0;i<MultipartFiles.length;i++) {
formData.append("files", MultipartFiles[i].raw);
}
formData.delete('createTime');
formData.delete('updateTime');
formData.delete('status');
return formData;
},
|