【问题标题】:Error HTTP Status 400 - The request sent by the client was syntactically incorrect错误 HTTP 状态 400 - 客户端发送的请求在语法上不正确
【发布时间】:2016-07-04 06:06:54
【问题描述】:

如何将json数据角度发送到spring控制器和返回值字符串.can do 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;
}

【问题讨论】:

    标签: angularjs spring


    【解决方案1】:

    请尝试删除 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");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-22
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多