0

In my spring controller, I have this:

@RequestMapping(value = "/users/{id}", method = RequestMethod.DELETE)
@ResponseBody
public void deleteUser(@RequestParam(value = "id") long id) throws Exception {
    users.delete(id); // It works on tests
}

Here I want to delete the passed user in the URL (from his ID).

In my AngularJS application, I have this module:

angular.module('app')
    .factory('DeleteUserService', function($resource) {
        return $resource('/users/:id', {id:'@id'}, {
            deleteUser: {
                method:'DELETE',
                headers : {'Content-Type': 'application/json'}
            }
        });
    });
});

I call the module from my user administration page, with this:

DeleteUserService.deleteUser({id:$scope.id}, function() { //$scope.id = 15
    console.log('Correctly deleted!');
});

The problem is that I get a 400 Bad Request error: DELETE http://localhost:8080/users/15 [HTTP/1.1 400 Required long parameter 'id' is not present 2ms]

I do not understand why my controller does not see the param :/

Could you help me finding the problem ?

Thanks, do not hesitate if you need additional code.

1

1 Answer 1

2

You have to use @PathVariable instead @RequestParam in that case.

Sign up to request clarification or add additional context in comments.

3 Comments

I think it's '@PathVariable', not '@PathParam'.
@PathParam is Jax-rs specific, OP does not mention jax-rs, only spring!
PathVariable works perfectly. PathParam also exists but is different. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.