我有一个简单的多对多关系:Owner <-> Book <-> Publisher
我注意到一种奇怪的行为:当我得到特定的Book
时,将获取Publisher
和Owner
(子实体)信息以及所有属性。但是,在Get
所有Book
中,子项的属性都丢失了。
当我对特定GET
进行Book
时,我会获得Book
及其子项的所有属性:
cURL -XGET http://localhost:8080/books/isbn/978-0743246264
{
"id":4,
"name":"Book 4",
"isbn":"978-0743246264",
"publishers":[
{
"id":1,
"name":"Publisher 1",
"description":"Description - 1"
}
],
"owners":[
{
"id":3,
"name":"Owner 3"
}
]
}
但是,当我为所有图书运行GET
时,某些元素缺少子属性:
cURL -XGET http://localhost:8080/books
[
{
"id":1,
"name":"Book 1",
"isbn":"978-0743246261",
"publishers":[
{
"id":1,
"name":"Publisher 1",
"description":"Description - 1"
},
{
"id":2,
"name":"Publisher 2",
"description":"Description - 2"
}
],
"owners":[
{
"id":1,
"name":"Owner 1"
}
]
},
{
"id":2,
"name":"Book 2",
"isbn":"978-0743246262",
"publishers":[
{
"id":4,
"name":"Publisher 4",
"description":"Description - 4"
},
1,
{
"id":3,
"name":"Publisher 3",
"description":"Description - 3"
}
],
"owners":[
{
"id":2,
"name":"Owner 2"
},
{
"id":3,
"name":"Owner 3"
},
1
]
},
{
"id":3,
"name":"Book 3",
"isbn":"978-0743246263",
"publishers":[
4,
2
],
"owners":[
2
]
},
{
"id":4,
"name":"Book 4",
"isbn":"978-0743246264",
"publishers":[
1
],
"owners":[
3
]
}
]
我已经在GitHub上设置了项目,它已准备好立即运行和测试:https://github.com/tekpartner/learn-spring-boot-many-2-many