Можно ли объединить Query-By-Example с методом данных пружины? - PullRequest
0 голосов
/ 28 марта 2019

У меня есть Template класс с несколькими полями (id,name,description,created,modified....)

и может фильтровать по дате создания, как показано ниже:

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

Мой пример такой:

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

Есть ли какой-нибудь возможный способ добавить Пример в метод findAllByCreatedBetween?

1 Ответ

0 голосов
/ 28 марта 2019
@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());
}

См. Ссылку:

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

...