title: Filtering findAll using Spring web and data
body: <p>While designing a new application using spring boot. I wanted to have rest end point for finding all entities with a filter like below</p>
  
  <p>GET <a href="http://foo.com/entities?firstName=test&amp;lastName=test2" rel="nofollow noreferrer">http://foo.com/entities?firstName=test&amp;lastName=test2</a></p>
  
  <p>The implementation looks like below.</p>
  
  <pre><code>@RequestMapping(value = /entities, method = RequestMethod.GET)
  public List&lt;Entity&gt; getAll(@RequestParam(value = "firstName", required = false) String firstName, @RequestParam(value = "lastName", required = false) String lastName) {
    if (firstName != null &amp;&amp; lastName != null) {
      return entityRepository.findByFirstNameAndLastName(firstName, lastName);
    } else if (firstName != null) {
      return entityRepository.findByFirstName(firstName);
    } else if (lastName != null) {
      return entityRepository.findByLastName(lastName);
    } else {
      return StreamSupport.stream(entityRepository.findAll().spliterator(), false).collect(Collectors.toList());
    }
  }
  </code></pre>
  
  <p>As we can see this gets a little out of hand if we have to add new parameters. What is the easiest way to mitigate this. Or should i change the design. I thought this was the standart practice?</p>
  
  <p>Note. The repository is a CRUDRepository with the added methods.</p>