删除时出现 400 Bad Request 错误
400 Bad Request error on Delete
我和我的 m8s 正在使用 Spring MVC、angularJS 等为我们的大学开发手稿处理系统。我们在从数据库中删除用户时遇到了一些问题。
我们总是得到 HTTP 状态 400 - 必需的字符串参数 'userName' 不存在
输入状态报告
消息必需的字符串参数 'userName' 不存在
说明客户端发送的请求语法不正确。
控制器:
@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());
});
};
您在 /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);
}
我和我的 m8s 正在使用 Spring MVC、angularJS 等为我们的大学开发手稿处理系统。我们在从数据库中删除用户时遇到了一些问题。
我们总是得到 HTTP 状态 400 - 必需的字符串参数 'userName' 不存在
输入状态报告
消息必需的字符串参数 'userName' 不存在
说明客户端发送的请求语法不正确。
控制器:
@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());
});
};
您在 /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);
}