Spring请求参数未从angular获取数据

Spring请求参数未从angular获取数据,angular,spring,spring-mvc,angular9,Angular,Spring,Spring Mvc,Angular9,我正在发送一个带有http参数的post请求,在服务器端,我在@Requestparm中接受该请求,但当我单击submit按钮时,我发现错误,因为所需的字符串参数“subjectId”不存在 我不知道为什么会出现这个错误,因为我在postman中测试同一个api时,它工作正常。我将表单数据从postman发送到test,工作正常。但不是从angular发送。可能是什么问题 角度后端服务代码: public postStudentAssignment(communication: Commun

我正在发送一个带有http参数的post请求,在服务器端,我在
@Requestparm
中接受该请求,但当我单击submit按钮时,我发现错误,因为
所需的字符串参数“subjectId”不存在
我不知道为什么会出现这个错误,因为我在postman中测试同一个api时,它工作正常。我将表单数据从postman发送到test,工作正常。但不是从angular发送。可能是什么问题

角度后端服务代码:

  public postStudentAssignment(communication: Communication){
    console.log(communication);
    // const headers = new HttpHeaders();
    // headers.append('Content-Type', 'application/json');
    // headers.append('Accept', 'application/json');

    let httpParams = new HttpParams()
    httpParams = httpParams.append('clientId',communication.clientId.toString())
    httpParams = httpParams.append('subjectId',communication.subjectId.toString())
    httpParams = httpParams.append('studentGradeDivisionId',communication.studentGradeDivisionId.toString())
    httpParams = httpParams.append('type',"Assignment")
    httpParams = httpParams.append('headline',communication.headline)
    httpParams = httpParams.append('communicationText',communication.communicationText)
    httpParams = httpParams.append('attachmentFileName',communication.attachmentFileName)
    httpParams = httpParams.append('attachment',communication.attachment)
    httpParams = httpParams.append('attachedPaperId',(!communication.attachedPaperId)?null:communication.attachedPaperId.toString())
    httpParams = httpParams.append('dueDate',communication.dueDate!=null?communication.dueDate.toString():null)
    httpParams = httpParams.append('isShared',communication.isShared.toString())
    httpParams = httpParams.append('createUserId',communication.createUserId.toString())
    console.log(httpParams)
    return this.http.post(BackendService.STUDENT_ASSIGNMENT,{parmas: httpParams, responseType:'text'});
   }
服务器端(spring)代码:

@预授权(“hasAnyRole('TEACHER'))
@后映射()
公共响应插入通信详细信息(
@RequestParam(“subjectId”)字符串subjectId,
@RequestParam(“studentGradeDivisionId”)字符串studentGradeDivisionId,
@RequestParam(“类型”)字符串类型,
@RequestParam(“标题”)字符串标题,
@RequestParam(“communicationText”)字符串communicationText,
@RequestParam(“attachmentFileName”)字符串attachmentFileName,
@RequestParam(“附件”)多部分文件附件,
@RequestParam(“attachedPaperId”)字符串attachedPaperId,
@RequestParam(“dueDate”)字符串dueDate,
@RequestParam(“isShared”)字符串isShared,
@RequestParam(“clientId”)字符串clientId,
@RequestParam(“createUserId”)长createUserId)引发ParseException{
通信到通信到=新通信到();
通信到.setType(类型);
通信到。设置主语(长值of(主语));
communicationDto.setStudentGradeDivisionId(Arrays.asList(studentGradeDivisionId.split(“,”).stream().map(s->Long.parseLong(s.trim()).collect(Collectors.toList());
通信到。设置标题(标题);
设置communicationText(communicationText);
通信到.setAttachmentFileName(attachmentFileName);
通信到。设置附件(附件);
通信到.setAttachedPaperId(Long.valueOf(attachedPaperId));
通信到.setClientId(Long.valueOf(clientId));
setCreateUserId(createUserId);
通信到.setDueDate(新的SimpleDateFormat(“dd/MM/yyyy”).parse(dueDate));
communicationDto.setIsShared(Integer.parseInt(isShared));
试一试{
设置冲突=validator.validate(communicationDto);
if(冲突.size()==0){
通讯dao.插入通讯详细信息(通讯到);
返回ResponseEntity.ok().body(“添加成功”);
}否则{
LOGGER.error(String.format(“无法插入通信详细信息,因为数据无效-%s”),
沟通);
for(约束冲突:冲突){
LOGGER.error(违反.getMessage());
}
返回null;
}
}捕获(例外e){
返回ResponseEntity.ok().body(e.getMessage());
}
}
这是打字错误吗

return this.http.post(BackendService.STUDENT_ASSIGNMENT,{parmas: httpParams, responseType:'text'});
我认为这应该是一个比较好的结果

return this.http.post(BackendService.STUDENT_ASSIGNMENT,{params: httpParams, responseType:'text'});
编辑:更糟糕的是:

return this.http.post(BackendService.STUDENT_ASSIGNMENT, null, { params: httpParams, responseType:'text' } });

您正在尝试发送查询参数还是正文?我正在发送查询参数post的第二个参数是正文,不是请求选项。我希望我的数据在请求参数内。我怎么做阅读我已检查urs代码,但仍然从服务器端获取相同的错误请求参数未获取subjectId。获取错误找不到名称选项删除“选项”当前请求不是多部分请求。此错误即将发生
return this.http.post(BackendService.STUDENT_ASSIGNMENT, null, { params: httpParams, responseType:'text' } });