springboot同时获得一个json数据包和图像
let formData = new FormData()
formData.append('patient', JSON.stringify({
name: vm.patientForm.name,
recordNo: vm.patientForm.recordNo,
relatedNo: vm.patientForm.relatedNo,
birthday: () => {
return vm.birthday ? vm.birthday.getTime() : null
},
age: vm.patientForm.age,
nation: vm.patientForm.nation,
sex: vm.patientForm.sex,
email: vm.patientForm.email,
phone: vm.patientForm.phone,
angleClassification: vm.patientForm.angleClassification,
address: vm.patientForm.address,
remarks: vm.patientForm.remarks
}))
let blobImage = vm.canvasDataURL ? vm.dataURLtoBlob(vm.canvasDataURL) : null
formData.append('avatarImage', blobImage, 'avatar.jpg')
vm.$http.post('/api/v1/patient', formData)
.then(response => {
console.log(response.data)
}).catch(() => {
vm.$message.warning('添加病历失败!')
})
@PostMapping("")
public RetResult addPatient(@RequestPart String patient, @RequestPart(required = false) MultipartFile avatarImage) throws IOException {
Patient patient1 = new ObjectMapper().readValue(patient, Patient.class);
return RetResultUtils.success(patient1);
}