#436 - Add Redis QbE (Query by Example) example.

This commit is contained in:
Mark Paluch
2018-09-24 09:50:49 -04:00
parent 01da5a94b9
commit aafe04db51
2 changed files with 18 additions and 1 deletions

View File

@@ -21,12 +21,13 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.geo.Circle;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
interface PersonRepository extends CrudRepository<Person, String> {
interface PersonRepository extends CrudRepository<Person, String>, QueryByExampleExecutor<Person> {
List<Person> findByLastname(String lastname);

View File

@@ -33,6 +33,7 @@ import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@@ -144,6 +145,21 @@ public class PersonRepositoryTests {
assertThat(aryaAndJon).containsOnly(arya, jon);
}
/**
* Find entities by {@link Example Query by Example}.
*/
@Test
public void findByQueryByExample() {
flushTestUsers();
Example<Person> example = Example.of(new Person(null, "stark", null));
Iterable<Person> starks = repository.findAll(example);
assertThat(starks).contains(arya, eddard).doesNotContain(jon);
}
/**
* Find entities in range defined by {@link Pageable}.
*/