在 MongoDB 中,我有一个名为 Customer 的文档集合,其中嵌入了客户定义的标签。我的域对象看起来像这样(包括 Lombok 注释):
@Document(collection = "Customer")
@Getter
@Setter
public class Customer {
@Id
long id;
@Field("name")
String name;
@Field("labels")
List<CustomerLabel> labels;
}
@Getter
@Setter
public class CustomerLabel {
@Id
@Field("label_id")
long labelId;
@Field("label_name")
String labelName;
}
现在,对的响应GET /customers
如下所示:
{
"_links": {
"self": {
"href": "http://localhost:8080/app/customers?page=&size=&sort="
}
},
"_embedded": {
"customers": [
{
"name": "Smith, Jones, and White",
"labels": [
{
"labelName": "General label for Smith, Jones, and White"
}
],
"_links": {
"self": {
"href": "http://localhost:8080/app/customers/285001"
}
}
}
]
},
"page": {
"size": 20,
"totalElements": 1,
"totalPages": 1,
"number": 0
}
}
我想将嵌入标签文档“调用”为单独的链接关系,以便响应GET /customers
看起来更像这样:
{
"_links": {
"self": {
"href": "http://localhost:8080/app/customers?page=&size=&sort="
}
},
"_embedded": {
"customers": [
{
"name": "Smith, Jones, and White",
"_links": [
{
"labels": {
"href": "http://localhost:8080/app/customers/285001/labels"
},
{
"self": {
"href": "http://localhost:8080/app/customers/285001"
}
}]
}
]
},
"page": {
"size": 20,
"totalElements": 1,
"totalPages": 1,
"number": 0
}
}
我怎样才能在我的应用程序中做到这一点?