gpt4 book ai didi

java - 休息资源 : get id of subentity without extra request

转载 作者:行者123 更新时间:2023-12-02 04:53:38 25 4
gpt4 key购买 nike

我有这样的实体:

@Entity
class MyEntity {
Long id;
SecondEntity second;
...
}

@Entity
class SecondEntity {
Long id;
...
}

我使用@RestResource作为rest-API。如果我请求 MyEntity 列表,我会得到如下结果:

{
"_links": {
"self": {"href": "http://localhost:8080/api/MyEntity/1"},
"second": {"href": "http://localhost:8080/api/MyEntity/1/second"}
}
},
{
"_links": {
"self": {"href": "http://localhost:8080/api/MyEntity/2"},
"second": {"href": "http://localhost:8080/api/MyEntity/2/second"}
}
}

如果我想检查,是[0].second == [1].second,我需要做两个额外的请求。这不太好。

也许可以配置 RestResource 来提供以下资源?

{
"_links": {
"self": {"href": "http://localhost:8080/api/MyEntity/1"},
"second": {"href": "http://localhost:8080/api/SecondEntity/12"}
}
},
{
"_links": {
"self": {"href": "http://localhost:8080/api/MyEntity/2"},
"second": {"href": "http://localhost:8080/api/SecondEntity/45"}
}
}

最佳答案

关于java - 休息资源 : get id of subentity without extra request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28993008/

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