简体   繁体   English

如何使用 Spring Rest 数据加载关系实体

[英]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 响应是下一个: 保留 api 响应以进行预订

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.

相关问题 如何通过自链接在 Spring Data REST 服务器中加载实体? - How to Load an Entity Inside a Spring Data REST Server by Self Link? 无法使用RestTemplate和Spring Data REST发布关系的新实体 - Unable to post new entity with relationship using RestTemplate and Spring Data REST Spring Data Rest-如何建立关联关系 - Spring Data Rest - How to have an association relationship spring-data-rest和微服务:在另一个spring-data-rest服务中与@OneToOne关系实体的实体 - spring-data-rest and micro-services: Entity with @OneToOne relationship with Entity in another spring-data-rest service Spring Data,REST和ManyToMany关系 - Spring Data, REST and ManyToMany relationship 如何使用Spring Data REST在OneToMany关系中添加对象 - How to add an object in a OneToMany relationship using Spring Data REST Spring Data Rest JPA - 无法延迟加载OneToMany双向关系 - Spring Data Rest JPA - Can't lazy load OneToMany bidirectional relationship 如何删除多对多关系中的子实体(Spring jpa rest 应用程序)而不删除父实体? - How to delete child entity in many to many relationship (Spring jpa rest app) without deleting the parent? Spring Data REST-如何通过JSON忽略字段对实体进行排序? - Spring Data REST - How to sort an entity by JSON ignored field? 如何通过具有弹簧数据休息的备用键公开实体 - How to expose an entity via alternate keys with spring data rest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM