是否有 JpaSpecificationExecutor 的响应式版本

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

我有以下代码,它使用

Specification
构建复杂的 where 子句。


public interface EmployeeRepository extends
    CrudRepository<Employee, String>,
    JpaSpecificationExecutor<Employee> {
}

public class Service {
    @Autowired
    private EmployeeRepository employeeRepository;


   public List<Employee> test() {
      return employeeRepository.findAll(where(hasNames(List.of("Tom", "Jerry"))).and(hasAges(List.of(20,21))));
   }
}

我正在尝试使用 r2dbc 将此代码转换为反应式。我用

CrudRepository
替换了
ReactiveCrudRepository
。然而,为了构建复杂的 where 子句,我需要使用
Specification
。我没有看到
JpaSpecificationExecutor

的反应式版本
public interface EmployeeRepository extends
    ReactiveCrudRepository<Employee, String>,
    JpaSpecificationExecutor<Employee> { // is there ReactiveJpaSpecificationExecutor?
}

是否有 JpaSpecificationExecutor 的反应式版本,或者以反应式构建此类 where 子句的方法?

jpa spring-data-jpa spring-data spring-data-r2dbc
2个回答
0
投票

我也在等待 Criteria,但现在没看到;-) 我需要实现 beetwen:Spring JPA ExampleMatcher 比较日期条件

另请参阅类似问题: https://github.com/spring-projects/spring-data-jpa/issues/1331 https://github.com/r2dbc/r2dbc-spi/issues/141

也许你现在可以使用模板: https://hantsy.medium.com/update-accessing-rdbms-with-spring-data-r2dbc-a4d118b1669d或infobip-spring-data-querydsl


0
投票

我为此使用 ReactiveQuerydslPredicateExecutor

@Repository
public interface EmployeeRepository extends ReactiveCrudRepository<Employee, Long>, ReactiveQuerydslPredicateExecutor<Employee> {
    
    Flux<Employee> findAll(Predicate predicate);
    Mono<Employee> findOne(Predicate predicate);
    Mono<Long> count(Predicate predicate);        
}
© www.soinside.com 2019 - 2024. All rights reserved.