mtumilowicz / springdata-qbe

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.


Languages

Language:Java 100.0%