假如人只能自己单独生活,只会考虑自己,他的痛苦将是难以承受的。——帕斯卡
代码很简单:
1
| userRepository.findBy(Example.of(new User()), x -> x.page(PageRequest.of(0, 1)))
|
这里repository
需要继承org.springframework.data.repository.query.ReactiveQueryByExampleExecutor
例如:
1 2 3 4 5 6 7 8
| 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> { }
|
使用:
1 2 3 4
| userRepository.findBy(Example.of(new User()), x -> x.page(PageRequest.of(0, 1))) .as(StepVerifier::create) .expectNextMatches(Streamable::isEmpty).verifyComplete();
|