Show how to use Limit with repository queries.
Add methods taking a Limit parameter to various samples. Original pull request: #672 Closes #671
This commit is contained in:
committed by
Mark Paluch
parent
e90be0c65b
commit
f98c7b9c93
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package example.springdata.mongodb.people;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Limit;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -37,6 +40,17 @@ public interface ReactivePersonRepository extends ReactiveCrudRepository<Person,
|
||||
*/
|
||||
Flux<Person> findByLastname(String lastname);
|
||||
|
||||
/**
|
||||
* Find at most the number of users defined via maxResults with the given lastname.
|
||||
* This method will be translated into a query by constructing it directly from the method name as there is no other
|
||||
* query declared.
|
||||
*
|
||||
* @param lastname
|
||||
* @param maxResults the maximum number of results returned.
|
||||
* @return
|
||||
*/
|
||||
Flux<Person> findByLastname(String lastname, Limit maxResults);
|
||||
|
||||
/**
|
||||
* String query selecting one entity.
|
||||
*
|
||||
|
||||
@@ -18,6 +18,7 @@ package example.springdata.mongodb.people;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.mongodb.util.MongoContainers;
|
||||
import org.springframework.data.domain.Limit;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -157,6 +158,14 @@ class ReactivePersonRepositoryIntegrationTest {
|
||||
repository.findByLastname("White").as(StepVerifier::create).expectNextCount(2).verifyComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit result size.
|
||||
*/
|
||||
@Test
|
||||
void shouldLimitResultSize() {
|
||||
repository.findByLastname("White", Limit.of(1)).as(StepVerifier::create).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data using a string query.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user