【发布时间】:2016-03-01 15:36:32
【问题描述】:
我正在使用 JPA 使用 Spring Boot 开发应用程序。 在应用程序中,我公开了一个休息 API。我不想使用 Spring data rest,因为我想完全控制数据。
我无法弄清楚如何动态使用 EntityGraph。
假设我有以下模型取自here
@Entity
class Product {
@ManyToMany
Set<Tag> tags;
// other properties omitted
}
interface ProductRepository extends Repository<Customer, Long> {
@EntityGraph(attributePaths = {"tags"})
Product findOneById(Long id);
}
我有以下链接可以访问产品 http://localhost:8090/product/1
它返回给我一个 id 为 1 的产品
问题:
- 默认情况下会像我们提到的@EntityGraph 那样获取标签吗? 如果是,那么可以按需配置吗?说,如果在查询中 字符串我有 include=tags,那么我只想获取产品 它的标签。
我找到了this 文章,但不确定这有什么帮助。
【问题讨论】:
-
如果您需要动态EntityGraphs,您可能对这个项目感兴趣:spring-data-jpa-entity-graph
标签: java spring jpa spring-data spring-data-jpa