Spring JPA 查询创建 - 将 By 与谓词一起使用
Spring JPA Query Creation - Using By with a Predicate
我想创建一个 Spring 使用默认条件和动态谓词的数据 JPA 查询。
例如使用客户实体:
findByFirstnameIn(List<String> names, Predicate predicate);
我在Spring Data JPA documentation
中找不到类似的例子
另一个解决方案是使用 do
findAll(predicate.and(customer.firstname.in(names)))
但我想避免这一行额外的代码。
你的第二种方法是正确的方法。您可能需要关注类似的功能请求
https://github.com/spring-projects/spring-data-jpa/issues/1524
我想创建一个 Spring 使用默认条件和动态谓词的数据 JPA 查询。
例如使用客户实体:
findByFirstnameIn(List<String> names, Predicate predicate);
我在Spring Data JPA documentation
中找不到类似的例子另一个解决方案是使用 do
findAll(predicate.and(customer.firstname.in(names)))
但我想避免这一行额外的代码。
你的第二种方法是正确的方法。您可能需要关注类似的功能请求 https://github.com/spring-projects/spring-data-jpa/issues/1524