1

我有一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方法?

4

1 回答 1

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());
}

请参阅此链接:

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

于 2019-03-28T15:06:48.417 回答