@RequestBody Map <string,object =“”>输入获取int值

时间:2017-03-04 12:38:46

标签: java angularjs spring-mvc spring-boot

@RequestMapping(path = "/registrationuser", method = RequestMethod.POST, produces=MediaType.APPLICATION_JSON_VALUE, consumes=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getUserDetails(@RequestBody Map<String, Object> input) throws commonException  {
    Map<String, Object> retMap = new HashMap<String, Object>();

    String email=(String) input.get("email");
    long id=(Long) input.get("userid");
    String password=(String) input.get("password");
    String rollid="1";
    User user = new User();
    user.setEmail(email);
    user.setId(id);
    user.setPassword(bCryptPasswordEncoder.encode(password));

    userRepository.save(user);

    ResponseEntity<Map<String, Object>> retValue = new ResponseEntity<Map<String,Object>>(retMap, HttpStatus.OK);
    return retValue;
}

===

$scope.saveUserFunction = function(myVar) {
  console.log($scope.edituserdetails.email);
  console.log($scope.edituserdetails.email);
  console.log($scope.edituserdetails.username);
  console.log($scope.edituserdetails.password);
   console.log($scope.edituserdetails.id);

  console.log($scope.token);
  //$scope.user = {};
  // calling our submit function.


        $http({
            method  : "POST",
            url     : "/registrationuser",
            data    : {
            "email"     : $scope.edituserdetails.email,
            "username": $scope.edituserdetails.username,
            "password"  : $scope.edituserdetails.password,
            "userid": $scope.edituserdetails.id
            }

           })
            .success(function(data) {
              if (data.errors) {

              } else {
              //  $scope.message = data.message;
              }
            });

}

});

获取用户ID的错误。为什么它是整数。我需要施展它吗?

1 个答案:

答案 0 :(得分:0)

您可以直接在春假中使用您的实体,例如:

@RequestBody User user

然后密码也可以重置。

此外,返回值不应为Map

return new ResponseEntity<User>(user, HttpStatus.OK);