I am using Spring Data for the paging and the sorting. However, I would like to perform multi-columns searches.
Now, I am using the annotation @Query in my r
All above the solutions are great, but we can also use Example and ExampleMatcher for multi column search
/* Build Search object */
Employee employee=new Employee();
employee.setFirstName(requestDTO.getFilterText());
employee.setLastName(requestDTO.getFilterText());
employee.setEmail(requestDTO.getFilterText());
/* Build Example and ExampleMatcher object */
ExampleMatcher customExampleMatcher = ExampleMatcher.matchingAny()
.withMatcher("firstName", ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase())
.withMatcher("lastName", ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase())
.withMatcher("email", ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase());
Example employeeExample= Example.of(employee, customExampleMatcher);
/* Get employees based on search criteria*/
employeetRepository.findAll(employeeExample, PageRequest.of(requestDTO.getCurrentPageNumber(), requestDTO.getPageSize(), Sort.by(requestDTO.getSortingOrderColumnName()).descending()));