我有这样的要求,即根据 id 从数据库中获取数据。该记录可以具有相同 id 和类型的多个值,因为它是历史类型。然而,我们使用的版本每次都会改变。我想要的和我得到的样本如下。我正在使用Java8
,rest-api
并json api
在其中使用注释标记关系属性。此数据是从数据库中保存和获取的,因此要成为完全唯一的行,id 和版本组合应该是唯一的。这意味着数据库中存在具有相同 id 但版本不同的记录
我想要的是:
{
"data":{
"id": "123",
"attributes":{
"name": "SJ"
},
"relationships":{
"contact":{
"data":[
{
"type":"test",
"id":"4567"
},
{
"type":"test",
"id":"4567"
}
]
}
}
},
"included":[
{
"type":"test",
"id":"4567",
"attributes":{
"testfield":"testfield 1",
"version": 0
}
},
{
"type":"test",
"id":"4567",
"attributes":{
"testfield":"testfield 2",
"version":1
}
}
]
}
我得到什么:
{
"data":{
"id": "123",
"attributes":{
"name": "SJ"
},
"relationships":{
"contact":{
"data":[
{
"type":"test",
"id":"4567"
},
{
"type":"test",
"id":"4567"
}
]
}
}
},
"included":[
{
"type":"test",
"id":"4567",
"attributes":{
"testfield":"testfield 1",
"version":1
}
}
]
}