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.

Mistalis
  • 17,793
  • 13
  • 73
  • 97
  • Use `@PathVariable` not `@RequestParam`. Here's an answer that explains the difference http://stackoverflow.com/questions/13715811/requestparam-vs-pathvariable – ikumen Jul 07 '15 at 17:12

1 Answers1

2

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

yivi
  • 42,438
  • 18
  • 116
  • 138