错误HTTP状态400 - 客户端发送的请求在语法上不正确

时间:2016-07-04 06:06:55

标签: angularjs spring

如何将json数据角度发送到spring控制器和返回值字符串.can可以做posibile ??。

  

HTML:姓氏:ng-model =“user.lastname”,   名字:ng-model =“user.firstname”,电子邮件:ng-model =“user.email”

Angular Js :
$http({
    method  : 'POST',
    url     : baseurl+'service/user/saveangular/',
    data    : JSON.stringify($scope.user), //forms user object   
    header  : {'Content-Type' :  'application/json; charset=UTF-8'}
}).success(function(response){
        $window.alert("Success");
});

Spring :
@RequestMapping(value="saveangular",method = RequestMethod.POST)
public @ResponseBody List<User> addusersangular(@RequestBody User user) {
    System.out.println("save user angular called");
    userService.addUser(user);
    List<User> users=userService.getAllUsers();
    return users;
}

1 个答案:

答案 0 :(得分:0)

请尝试删除JSON.stringify()函数调用,因为这会将您的JSON转换为JSON字符串。

$http({
    method  : 'POST',
    url     : baseurl+'service/user/saveangular/',
    data    : $scope.user, //forms user object   
    header  : {'Content-Type' :  'application/json; charset=UTF-8'}
}).success(function(response){
        $window.alert("Success");
});