Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 带有文件控件的表单数据未上载_Spring Boot_Angular4 Forms - Fatal编程技术网

Spring boot 带有文件控件的表单数据未上载

Spring boot 带有文件控件的表单数据未上载,spring-boot,angular4-forms,Spring Boot,Angular4 Forms,我正在尝试使用angular4和spring boot上传一个包含文件和表单数据的表单。我将内容类型设置为multipart/formdata,但仍然显示400错误 我有棱角的一侧是 this.formobj["userID"] = this.userId; this.formobj["userName"] = this.addfrm.value.userName; this.formobj["userDescription"] = this.addfrm.value.userDes; this

我正在尝试使用angular4和spring boot上传一个包含文件和表单数据的表单。我将内容类型设置为
multipart/formdata
,但仍然显示400错误

我有棱角的一侧是

this.formobj["userID"] = this.userId;
this.formobj["userName"] = this.addfrm.value.userName;
this.formobj["userDescription"] = this.addfrm.value.userDes;
this.formobj["files"] = this.addfrm.value.image;

let type = new HttpHeaders();
type.append('Content-Type', 'multipart/form-data');


this.http.post(this.Core_URL + '/updateUserWithFile', this.formobj, {headers: type})
  .subscribe(data => {
    console.log("** form submited");
    console.log(data);
    this.clearShareObj();
    this.r.navigateByUrl('home');
  });
 public class UserInfo {
 private Integer userID;
 private String userName;
 private String userDescription;
 private MultipartFile[] files;
 }
}

服务器端

服务器端我使用的是spring boot

@PostMapping("/updateUserWithFile")
private FunctionInfo updateUserWithFile(@RequestBody  UserInfo  userInfo) {
   System.out.println("ok");
   int userId = userInfo.getUserId();
   String userName = userInfo.getUserName();
   MultipartFile[] files; = userInfo.getFile();
}
域类

this.formobj["userID"] = this.userId;
this.formobj["userName"] = this.addfrm.value.userName;
this.formobj["userDescription"] = this.addfrm.value.userDes;
this.formobj["files"] = this.addfrm.value.image;

let type = new HttpHeaders();
type.append('Content-Type', 'multipart/form-data');


this.http.post(this.Core_URL + '/updateUserWithFile', this.formobj, {headers: type})
  .subscribe(data => {
    console.log("** form submited");
    console.log(data);
    this.clearShareObj();
    this.r.navigateByUrl('home');
  });
 public class UserInfo {
 private Integer userID;
 private String userName;
 private String userDescription;
 private MultipartFile[] files;
 }
提交后,向我显示以下标题。未设置内容类型


使用以下代码设置标题。这可能对你有帮助

import { Http, Headers } from '@angular/http';

在你的方法中使用

const headers = new Headers({'Content-Type', 'multipart/form-data'});

return this.http.post(this.Core_URL + '/updateUserWithFile', this.formobj, 
{headers: headers})
.subscribe(data => {
    console.log("** form submited");
    console.log(data);
    this.clearShareObj();
    this.r.navigateByUrl('home');
});