是否可以使用示例实体创建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之外还有其他选择吗?
你可以尝试类似的东西
List<Tuple> searchResults = queryFactory.selectFrom(customer)
.where(customer.name.eq(customerExample.getName()), customer.country.eq(customerExample.getCountry())
.fetch();
此外,它将返回List<Tuple>
而不是'Customer'。因此,您必须在之后将结果映射到“客户”。