相关疑难解决方法(0)

如何在Spring Boot中动态获取EntityGraph

我正在使用JPA使用Spring Boot开发应用程序.在应用程序中,我公开了一个rest API.我不想使用Spring数据休息,因为我想完全控制数据.

我无法弄清楚如何动态使用EntityGraph.

假设我从这里采取了以下模型

   @Entity
class Product {

  @ManyToMany
  Set<Tag> tags;

  // other properties omitted
}

interface ProductRepository extends Repository<Customer, Long> {

  @EntityGraph(attributePaths = {"tags"})
  Product findOneById(Long id);
}
Run Code Online (Sandbox Code Playgroud)

我有以下休息链接访问产品 http:// localhost:8090/product/1

它返回给我一个id为1的产品

问题:

  1. 默认情况下是否会像我们提到的那样提取标签 @EntityGraph?如果是,那么可以按需配置吗?比如说,如果在查询字符串中我有include = tags,那么我只想用其标签获取产品.

我找到了这篇文章,但不确定这有多大帮助.

java spring jpa spring-data spring-data-jpa

5
推荐指数
2
解决办法
6173
查看次数

标签 统计

java ×1

jpa ×1

spring ×1

spring-data ×1

spring-data-jpa ×1