Skip to content

mtumilowicz/springdata-qbe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

springdata-qbe

The main goal of this project is to explore basics of Query By Example API in Spring Data environment.

Reference: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example

manual

  1. matching with non null fields

    Customer customer = // init pattern fields
    
    Example<Customer> customerExample = Example.of(customer);
    
    customerRepository.findOne(customerExample)
    
  2. matching with null fields (remember to exclude id field - if it stays the result will be empty)

    ExampleMatcher matcher = matching()
            .withIncludeNullValues()
            .withIgnorePaths("id"); // and other fields that we don't want to have null in result
    
    Customer customer = // init pattern fields
    
    Example<Customer> customerExample = Example.of(customer, matcher);
    
    customerRepository.findOne(customerExample)
    
  3. matching with:

    • ignoring case
    • starts with
    • ends with
    ExampleMatcher matcher = matching()
                    .withIgnoreCase()
                    .withMatcher("firstName", GenericPropertyMatcher::startsWith)
                    .withMatcher("lastName", GenericPropertyMatcher::endsWith);
    
    Customer customer = Customer.builder()
                    .firstName("m")
                    .lastName("wicz")
                    .build();
    
    Example<Customer> customerExample = Example.of(customer, matcher);
            
    customerRepository.findOne(customerExample);
    

About

The main goal of this project is to explore basics of Query By Example API in Spring Data environment.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages