【问题标题】:@RequestBody Map<String, Object> input getting int value@RequestBody Map<String, Object> 输入获取 int 值
【发布时间】:2017-07-24 13:57:05
【问题描述】:
@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 出现以下错误。为什么它是整数。我也需要施放它吗?

【问题讨论】:

    标签: java angularjs spring-mvc spring-boot


    【解决方案1】:

    您可以直接在 spring-rest 中使用您的实体,例如:

    @RequestBody User user
    

    之后也可以重置密码。

    返回值也不应该是Map

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2023-03-25
      • 2017-06-11
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      相关资源
      最近更新 更多