如何将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;
}
答案 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");
});