【发布时间】:2015-11-02 06:20:19
【问题描述】:
我是春天的新手。
我有三个实体Invoice, Line and Product。
(1) 如果我打电话给GET /invoices,那么我想要像这样的输出,
{
"invoices": [
{
"id": "101",
"date": "2013-02-14"
},
{
"id": "102",
"date": "2013-02-18"
}
]
}
我已经这样做了,我可以这样做,但无法在获取请求中包含关系。
(2) 我想 GET 调用类似这样的包含关系的东西。
GET /invoices?include=invoice.lines:embed,invoice_line.product:sideload
我想要像这样的输出
{
"invoices": [
{
"id": "101",
"date": "2013-02-14",
"lines": [
{
"id": "201",
"product_id": "301",
"amount": 100
},
{
"id": "201",
"product_id": "302",
"amount": 100
}
]
},
{
"id": "102",
"date": "2013-02-18",
"lines": [
{
"id": "203",
"product_id": "301",
"amount": 100
}
]
}
],
"products": [
{
"id": "301",
"name": "Ice Cream"
},
{
"id": "302",
"name": "Waffles"
}
]
}
我陷入了(2)包含关系,我想实现这样的目标 需要帮忙。 提前致谢。
【问题讨论】:
-
最好的方法是在你的控制器中处理这个问题,使用
@RequestParam('include'),然后用你想要的正确格式发送一个响应
标签: java hibernate spring-mvc spring-boot