Spring + Angularjs can't change post to put

Viewed 45

When I use post method it works fine, but when I try to change it to put server do not recieve object.

UserController.java:

@RequestMapping(value = "/user/{user}", method = RequestMethod.POST)
    public ResponseEntity<User> updateUser(@ModelAttribute User user) {
        userService.updateRow(user);
        return new ResponseEntity<User>(user, HttpStatus.OK);
    }

user_service.js:

updateUser: function(user, id){

                    return $http.post('http://localhost:8080/user/', user)
                        .then(
                        function (response) {
                            return response.data;
                        },
                        function (errResponse) {
                            console.error('Error while updating user');
                            return $q.reject(errResponse);
                        }
                    );

            },

How can I change it to put method?

Using PUT:

UserController.java:

 @RequestMapping(value = "/user/{user}", method = RequestMethod.PUT)
    public ResponseEntity<User> updateUser(@RequestBody User user) {
        userService.updateRow(user);
        return new ResponseEntity<User>(user, HttpStatus.OK);
    }

user_service.js:

  updateUser: function(user, id){
                    return $http.put('http://localhost:8080/user/', user)
                        .then(
                        function (response) {
                            return response.data;
                        },
                        function (errResponse) {
                            console.error('Error while updating user');
                            return $q.reject(errResponse);
                        }
                    );

            },
1 Answers
Related