title: Spring Boot REST WebService + JPA : pageable and filter
body: <p>I'm fairly new to these technos and I need a pitch to understand a good way to do things. 
  I've got an Employee entity, and I want to list them by making a GET query to an endpoint.I have to return a Page of Employees, after having applied filters on field(s). Currently, the Pageable on the GET query works, but not my filter.</p>
  
  <p><strong>Here is my REST endpoint :</strong></p>
  
  <pre><code>@RequestMapping(value = "/employees",
              method = RequestMethod.GET,
              produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  @Transactional(readOnly = true)
  public ResponseEntity&lt;List&lt;EmployeeDTO&gt;&gt; getAllEmployees(Pageable pageable, String filters) throws URISyntaxException, JSONException {
  
          JSONObject sfilters = null;
          try {
              sfilters = new JSONObject(filters.trim());
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          // I wish this on could works, but still have to update it if we add fields to our Employee entity
          Page&lt;Employee&gt; page = employeeRepository.findAllByCompanyIdAndFirstnameLikeAndLastnameLike(
              userService.getUserWithAuthorities().getCompany().getId(),
              sfilters.get("firstname").toString(),
              sfilters.get("lastname").toString(),
              pageable);
  
          HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/employees");
          ResponseEntity&lt;List&lt;EmployeeDTO&gt;&gt; result = new ResponseEntity&lt;&gt;(page.getContent().stream()
              .map(employeeMapper::employeeToEmployeeDTO)
              .collect(Collectors.toCollection(LinkedList::new)), headers, HttpStatus.OK);
  
          return result;
  }
  </code></pre>
  
  <p>NB : I have to filter on more fields than that but I want to keep example as clear as possible.</p>
  
  <p><strong>My repository method :</strong></p>
  
  <pre><code>Page&lt;Employee&gt; findAllByCompanyIdAndFirstnameLikeAndLastnameLike(Long idCompany, String firstname, String lastname, Pageable pageable);
  </code></pre>
  
  <p>Client side, it works well, I send good params for pageable and for my filter to be converted into JSONObject. But now I need suggestions on how can I properly generate dynamics filters on my query. My JPA repository method doesnt work.</p>
  
  <p>I tried to use predicates, but it does not help as the methods fail when I give it a Predicate arg. This method seems to be good to check, items by items, if one or more match your pred but not sure they are made for retrieve set of items with a dynamic query.</p>
  
  <p><strong>EDIT</strong> : I created an EmployeeSpecification class implementing Specification but I want to return a list/array of Predicates not only one. The default method to override thus return a single Predicate. How can I manage to get multiple predicate from this entity ?</p>
  
  <p>Thanks for any hint, helps, past experiences to share.</p>