我有一个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
方法中?
答案 0 :(得分: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());
}
查看此链接: