代码很简单:
userRepository.findBy(Example.of(new User()), x -> x.page(PageRequest.of(0, 1)))
这里repository
需要继承org.springframework.data.repository.query.ReactiveQueryByExampleExecutor
例如:
import org.springframework.data.r2dbc.repository.R2dbcRepository; import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; import org.springframework.stereotype.Repository; import reactor.core.publisher.Flux; @Repository public interface UserRepository extends R2dbcRepository<User, Long>, ReactiveQueryByExampleExecutor<User> { }
使用:
userRepository.findBy(Example.of(new User()), x -> x.page(PageRequest.of(0, 1))) .as(StepVerifier::create) .expectNextMatches(Streamable::isEmpty).verifyComplete();