【发布时间】:2018-06-12 05:18:40
【问题描述】:
我无法将多部分文件和两个文本字段从角度发布请求发送到弹簧控制器。
我的发帖请求如下,
$scope.data = {
"file": $scope.uploadFile,
"doucmentType" : $scope.documentType,
"otherDocumentType" : $scope.otherDocumentType
}
其中 $scope.uploadFile 是文件对象,doucmnetType 和 otherDocumentType 是我希望与文件一起发送到 spring 控制器的两个文本字段。
post请求如下,
$http.post(appPath + '/temp/uploadAttachments',JSON.stringify($scope.data) ).success(function(result) {
});
我的spring控制器如下,
@RequestMapping(value = "uploadAttachments", method = RequestMethod.POST)
@ResponseBody
public String uploadAttachments(@RequestBody ReqParam reqParam) {
JSONObject ret= new JSONObject();
ret.put("result", true);
return ret.toString();
}
其中 ReqParam 是 pojo 类,包含文件的 getter 和 setter 以及其他字段,例如,
private MultipartFile file;
private String doucmentType;
private String otherDocumentType;
public String getOtherDocumentType() {
return otherDocumentType;
}
public void setOtherDocumentType(String otherDocumentType) {
this.otherDocumentType = otherDocumentType;
}
public String getDoucmentType() {
return doucmentType;
}
public void setDoucmentType(String doucmentType) {
this.doucmentType = doucmentType;
}
public MultipartFile getFile() {
return file;
}
public void setFile(MultipartFile file) {
this.file = file;
}
谢谢
【问题讨论】:
标签: java angularjs spring spring-mvc