Reputation:
Me and my m8s are developing a manuscript handling system for our university using Spring MVC,angularJS etc. We have some issues with deleting a user from the database.
We get always HTTP Status 400 - Required String parameter 'userName' is not present
type Status report
message Required String parameter 'userName' is not present
description The request sent by the client was syntactically incorrect.
Controller:
@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/delete/{userName}", method = RequestMethod.DELETE)
public void deleteUser(@RequestParam String userName) {
LOGGER.info("Deleted user: " + userName);
userManagerService.deleteUser(userName);
}
Method of the ManuscriptAdminService.js:
function deleteUser(userName){
$log.info("Delete selected user "+new Date());
$http.delete('delete/'+userName).then(function(data){
console.log(data);
},function(error){
$log.error("Error occured while admin tried to delete user "+new Date());
});
}
Method of the ManuscriptAdminController.js
vm.showModalUserDelete = function(index) {
$log.info("Show user delete modal "+new Date());
var modelInstance = $modal
.open({
animation : true,
templateUrl : 'htmlcontent/content/admin/modal/userDeleteManageModal.html',
controller : 'ManuscriptAdminModalinstacneController',
controllerAs : 'ManuscriptAdminModalinstacneController',
size : 300,
resolve : {
items : function() {
return ManuscriptAdminService.getUserName(index);
}
}
});
modelInstance.result.then(function (result) {
ManuscriptAdminService.deleteUser(result);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
Upvotes: 0
Views: 4182
Reputation: 3355
You're using a URI template variable in /delete/{userName}
, so you will need to use @PathVariable
annotation on your parameter:
@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/delete/{userName}", method = RequestMethod.DELETE)
public void deleteUser(@PathVariable String userName) {
LOGGER.info("Deleted user: " + userName);
userManagerService.deleteUser(userName);
}
Upvotes: 3