1、 js:
import httpRequest from '@/libs/httpRequest'
export const addTest= (entity) => {
return httpRequest.request({
url: '/api/addTest',
method: 'post',
headers: { 'Content-Type': 'multipart/form-data' },
data: entity
})
}
2、vue:
async addTest111() {
var fileFormData = new FormData()
for (let i = 0; i < this.testFiles.length; i++) {
fileFormData.append('testFiles', this.testFiles[i])
}
fileFormData.append('entity', JSON.stringify(this.entity))
await addTest(fileFormData).then((response) => {
if (response.status === 200) {
this.$Modal.success({
title: '提示:',
content: '成功'
})
} else {
this.$Modal.error({
title: '提示:',
content: '失败'
})
}
})
},
3、spring
@PostMapping("/api/addTest")
public void addTest(@RequestParam("testFiles")List<MultipartFile> files, @RequestParam("entity") String strEntity, Authentication authentication) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Entity entity = mapper.readValue(strEntity, Entity.class);
}