当我发送请求时,数据参数之一(newUsers)始终为空。
没有引发异常,但是服务器日志告诉我,在bean的所有字段中,只有projectId和groupName不为null。 '$ scope.projectTeam'是对象的数组,就是区别。
AngularJS部分:
$scope.saveChangesInProject = function (userId) {
if ($scope.projectTeam != null) {
// From the logs I know my scope.projectTeam contains all the chosen users
$http({
method: 'POST',
url: '/app/project/saveProject',
data: {
projectId: $routeParams.projectId,
newUsers: $scope.projectTeam,
groupName: "qwerty123",
}
});
}
}
Spring方法声明:
@RequestMapping(value = "/saveProject", method = RequestMethod.POST)
@Transactional(isolation = Isolation.SERIALIZABLE)
ResponseEntity<Project> saveProject(@RequestBody (required = true) ProjectBean projectBean) throws HibernateValidationException;
Java bean:
@Component
public class ProjectBean {
private Long id;
private Long projectId;
private String groupName;
private List<User> newUsers;
// getters and setters etc
我尝试使用FormData进行此操作,但出现“缺少所需的请求正文内容”。还尝试了Angular.toJson()。