gpt4 book ai didi

java - 使用 Angular 从 HAL 表示中获取 id

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:14 25 4
gpt4 key购买 nike

我如何从 Hal 表示中获取任何对象 ID?

我确实想从 allUser 列表中的特定用户那里获取此信息。有例子:

{
"_embedded" : {
"users" : [ {
"login" : "user1",
"firstName" : "Bolek",
"lastName" : "Kowal",
"email" : null,
"password" : null,
"gender" : null,
"birthDate" : null,
"_links" : {
"self" : {
"href" : "http://localhost:8080/games-organizer/api/users/1"
},
"user" : {
"href" : "http://localhost:8080/games-organizer/api/users/1"
},
"roles" : {
"href" : "http://localhost:8080/games-organizer/api/users/1/roles"
}
}
}, {
"login" : "user2",
"firstName" : "Lolek",
"lastName" : "Kowalski",
"email" : null,
"password" : null,
"gender" : null,
"birthDate" : null,
"_links" : {
"self" : {
"href" : "http://localhost:8080/games-organizer/api/users/2"
},
"user" : {
"href" : "http://localhost:8080/games-organizer/api/users/2"
},
"roles" : {
"href" : "http://localhost:8080/games-organizer/api/users/2/roles"
}
}
}

最终我如何使用rest spring api 和 Angular/Spring 删除特定用户?我不知道如何在没有任何用户(对象)的 id 的情况下执行此操作。

更新:

我想使用这个 id,调用这样的方法:

$scope.$on('deleteUser', function (event, id) {
userService.delete({id: id}).$promise.then(
function () {
// Broadcast the event to refresh the grid.
$rootScope.$broadcast('refreshUserGrid');
// Broadcast the event to display a delete message.
$rootScope.$broadcast('userDeleted');
$scope.clearForm();
},
function () {
// Broadcast the event for a server error.
$rootScope.$broadcast('error');
});

});

我想从 springRestAPI 的数据库中删除一些记录。

最佳答案

假设您想删除 user2 的详细信息,那么您可以这样做:

  For (var i=0;i<allUser.users.length;i++){
if(allUser.users[i].login=="user2"){
allUser.users.splice(i-1,i);
}
}

关于java - 使用 Angular 从 HAL 表示中获取 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46775632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com