1

I have a Template class with several fields (id,name,description,created,modified....)

and can filter by created date like below:

public interface TemplateRepository extends JpaRepository<Template, Long> {
    Page<Template> findAllByCreatedBetween(OffsetDateTime createdStart, OffsetDateTime createdEnd, Pageable pageable);
}

My Example like this:

ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll()
                .withIgnoreCase()
                .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
                .withIgnoreNullValues()
                .withIgnorePaths("id");
Example<Template> templateExample = Example.of(requestTemplate, exampleMatcher);        

Is there any possible way to add the Example into findAllByCreatedBetween method?

Viet
  • 3,349
  • 1
  • 16
  • 35

1 Answers1

0
@Test
public void givenPassengers_whenFindByExampleCaseInsensitiveMatcher_thenExpectedReturned() {
    ExampleMatcher caseInsensitiveExampleMatcher = ExampleMatcher.matchingAll().withIgnoreCase();
    Example<Passenger> example = Example.of(Passenger.from("fred", "bloggs", null),
      caseInsensitiveExampleMatcher);

    Optional<Passenger> actual = repository.findOne(example);

    assertTrue(actual.isPresent());
    assertEquals(Passenger.from("Fred", "Bloggs", 22), actual.get());
}

See this link:

https://www.baeldung.com/spring-data-query-by-example

jonas.lima
  • 116
  • 11