小编Mar*_*tin的帖子

Spring Data JPA按示例查询,可以访问嵌套的对象属性

我使用Query by Example并想知道如何在嵌套对象中找到具有某些属性的对象.

有人计划吗?

这是我的示例代码:

    ExampleMatcher matcher = ExampleMatcher.matching()
      .withMatcher("offer2product.id.productId", match -> match.exact()
              );

    Offer2ProductId id = new Offer2ProductId();
    id.setProductId(1337L);

    Offer2Product offer2Product = new Offer2Product();
    offer2Product.setId(id);

    Set<Offer2Product> offer2productSet = new HashSet<>();
    offer2productSet.add(offer2Product);

    Offer probe = new Offer();
    probe.setOffer2productSet(offer2productSet);

    Example<Offer> example = Example.of(probe, matcher);
    List<Offer> offerList = offerRepository.findAll(example);
Run Code Online (Sandbox Code Playgroud)

spring nested object spring-data-jpa spring-boot

5
推荐指数
1
解决办法
965
查看次数

标签 统计

nested ×1

object ×1

spring ×1

spring-boot ×1

spring-data-jpa ×1