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.