title: Spring Data ExampleMatchers by Example
body: <p>I'm trying to understand how to use Spring Data's <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example.matchers" rel="noreferrer">Query by Example</a> capabilities, and am struggling to understand how to use <a href="https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/ExampleMatcher.html" rel="noreferrer"><code>ExampleMatcher</code></a> and its various <code>with*</code> methods. Classic examples of the matcher in use includes snippets like this:</p>
  
  <pre><code>Person person = new Person();                          
  person.setFirstname("Dave");                           
  
  ExampleMatcher matcher = ExampleMatcher.matching()     
    .withIgnorePaths("lastname")                         
    .withIncludeNullValues()                             
    .withStringMatcherEnding();                          
  
  Example&lt;Person&gt; example = Example.of(person, matcher);
  </code></pre>
  
  <p>For some reason, I just can't wrap my brain around this DSL. Let's take the <code>Person</code> example from the docs. Let's say a <code>Person</code> entity looks like this:</p>
  
  <pre><code>// Pseudo code; omitting JPA annotations for this example
  public class Person {
      private String firstName;
      private String lastName;
      private Date dob;
      private Long score;
  
      // Getters, setters &amp; constructor omitted
  }
  </code></pre>
  
  <p>Can anyone show me an example of how to construct an <code>ExampleMatcher</code> that would allow me to find <code>Person</code> records meeting the following criteria:</p>
  
  <ul>
  <li>First name starts with "<em>Sme</em>"; and</li>
  <li>Last name is less than 10 characters long; and</li>
  <li>Date of birth is before 1970-01-01; and</li>
  <li>Score is between 10 and 20, inclusively</li>
  </ul>
  
  <p><strong>If any of these criteria aren't possible with <code>ExampleMatcher</code>, that's fine, but can someone show me which ones are or explain what methods might get me <em>close</em> to what I'm looking for?</strong></p>