我有一种方法可以在QueryDSL中找到示例吗?

问题描述 投票:0回答:1

是否可以使用示例实体创建QueryDSL谓词?例如:

Customer customerExample = new Customer();
customerExample.setName("John");
customerExample.setCountry("EUA");
QCustomer customer = QCustomer.customer;
Customer bob = queryFactory.selectFrom(customer)
  .where(customer.example(customerExample )) // matches customers with name like "John" and country like "EUA"
  .fetch();

如果没有,除了使用Spring JPA之外还有其他选择吗?

java jpa querydsl
1个回答
0
投票

你可以尝试类似的东西

List<Tuple> searchResults = queryFactory.selectFrom(customer)
      .where(customer.name.eq(customerExample.getName()), customer.country.eq(customerExample.getCountry())
      .fetch();

此外,它将返回List<Tuple>而不是'Customer'。因此,您必须在之后将结果映射到“客户”。

© www.soinside.com 2019 - 2024. All rights reserved.