我和我的m8正在使用Spring MVC,angularJS等为我们大学开发一个手稿处理系统。我们在从数据库中删除用户时遇到了一些问题。
我们始终获得HTTP状态400 - 必需字符串参数' userName'不存在
输入状态报告
message必需字符串参数' userName'不存在
description客户端发送的请求在语法上是不正确的。
控制器:
@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/delete/{userName}", method = RequestMethod.DELETE)
public void deleteUser(@RequestParam String userName) {
LOGGER.info("Deleted user: " + userName);
userManagerService.deleteUser(userName);
}
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());
});
}
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());
});
};
答案 0 :(得分:1)
您在/delete/{userName}
中使用了URI模板变量,因此您需要在参数上使用@PathVariable
注释:
@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/delete/{userName}", method = RequestMethod.DELETE)
public void deleteUser(@PathVariable String userName) {
LOGGER.info("Deleted user: " + userName);
userManagerService.deleteUser(userName);
}