[英]How to load relationship Entity with Spring Rest Data
I'm working in my learn project with AngularJS and Spring Rest Data.我正在我的学习项目中使用 AngularJS 和 Spring Rest Data。 I have the database tables Reservation and Client, a Reservation has a Client, perfect ... the JSON response for a Reservation query is the next:
我有数据库表 Reservation 和 Client,一个 Reservation 有一个 Client,完美...... Reservation 查询的 JSON 响应是下一个:
In yellow, it's the Client URL reference, I want to know if there any way to load this Client object to the response, some like the Jackson way (load the object and the intern object data, not a link), I know that it's the way with Spring Rest Data, but I'm confused by the way in that I should do this.黄色的是客户端 URL 引用,我想知道是否有任何方法可以将此客户端对象加载到响应中,有些类似于 Jackson 方式(加载对象和实习生对象数据,而不是链接),我知道它是Spring Rest Data 的方式,但我对我应该这样做的方式感到困惑。
In my Angular Controller I have this:在我的 Angular 控制器中,我有这个:
And, in the view (I wish .. ) I load the client data, but obviously not have data (because I didn't query the client link)而且,在视图中(我希望 .. )我加载了客户端数据,但显然没有数据(因为我没有查询客户端链接)
The client view (table) looks like this (client data not shown)客户端视图(表)如下所示(客户端数据未显示)
Please help me :) Thanks a lot!请帮助我:) 非常感谢!
You can use @Projection class to get relationship table data.您可以使用@Projection 类来获取关系表数据。 Projection class allow change JSON response format.
投影类允许更改 JSON 响应格式。 As below picture, I can get project's data related with sprint.
如下图,我可以得到与sprint相关的项目数据。
I create SprintProjection class:我创建 SprintProjection 类:
And I add projection class to Repository:我将投影类添加到存储库:
Here is source code sample: https://github.com/spring-projects/spring-data-examples/tree/master/rest/projections这是源代码示例: https : //github.com/spring-projects/spring-data-examples/tree/master/rest/projections
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.