[英]Is it possible to combine Query-By-Example with spring data method?
I have a Template
class with several fields (id,name,description,created,modified....)
我有一个带有几个字段的
Template
类(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? 有没有可能的方法将示例添加到
findAllByCreatedBetween
方法?
@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 https://www.baeldung.com/spring-data-query-by-example
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.