本文整理汇总了Java中org.springframework.data.domain.ExampleMatcher类的典型用法代码示例。如果您正苦于以下问题:Java ExampleMatcher类的具体用法?Java ExampleMatcher怎么用?Java ExampleMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExampleMatcher类属于org.springframework.data.domain包,在下文中一共展示了ExampleMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateAddress
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
public Address validateAddress(AddressDTO addressDTO) {
Address addressToSearch = new Address(addressDTO.getCountry(), addressDTO.getCity(), addressDTO.getPostcode(),
addressDTO.getStreet(), addressDTO.getStreetNumber());
//@formatter:off
ExampleMatcher matcher =
ExampleMatcher.matching()
.withMatcher("country", startsWith().ignoreCase())
.withMatcher("postcode", startsWith().ignoreCase())
.withMatcher("street", contains().ignoreCase())
.withMatcher("streetNumber", contains().ignoreCase())
.withMatcher("city", contains().ignoreCase());
//@formatter:on
Example<Address> searchExample = Example.of(addressToSearch, matcher);
return addressRepository.findOne(searchExample);
}
示例2: savePosts
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
/**
* Saves a collection of posts.
*
* @param posts A list of posts.
*/
protected void savePosts(List<Post> posts) {
int inserted = 0;
for (Post p : posts) {
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("url", ExampleMatcher.GenericPropertyMatchers.exact());
if (!postRepository.exists(Example.of(p, matcher))) {
logger.info("Inserting " + p.getUrl());
savePost(p);
inserted++;
} else {
logger.info("Duplicate post. Not inserted " + p.getUrl());
}
}
logger.info("Inserted " + inserted + " items");
}
示例3: testFindByExample
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Test
public void testFindByExample() {
User u = new User();
u.setEmailAddress("YUANXUEGUI");
List<User> result1 = repository.findAll(Example.of(u, ExampleMatcher.matchingAll()
.withIgnoreCase(true)
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)));
assertEquals(1, result1.size());
assertEquals("Yuan", result1.get(0).getFullName().getLastName());
assertThat(result1, hasItem(user));
List<User> result2 = repository.findAll(Example.of(u, ExampleMatcher.matchingAll()
.withIgnoreCase(false)
.withStringMatcher(ExampleMatcher.StringMatcher.EXACT)));
assertEquals(0, result2.size());
}
示例4: testExample
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Test
public void testExample() {
UserEntity admin = new UserEntity();
admin.setUserName("example");
admin.setLoginName("example");
admin.setPassword(BCryptPassWordUtils.encode("example"));
admin.setEmail("[email protected]");
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("userName", endsWith())
.withMatcher("loginName", startsWith().ignoreCase());
Example<UserEntity> example = Example.of(admin, matcher);
MyFastJsonUtils.prettyPrint(userRepository.findAll(example));
System.out.println(userRepository.count(example));
}
示例5: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<UseCase1DTO> findAll(PageRequestByExample<UseCase1DTO> req) {
Example<UseCase1> example = null;
UseCase1 useCase1 = toEntity(req.example);
if (useCase1 != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(UseCase1_.dummy.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(useCase1, matcher);
}
Page<UseCase1> page;
if (example != null) {
page = useCase1Repository.findAll(example, req.toPageable());
} else {
page = useCase1Repository.findAll(req.toPageable());
}
List<UseCase1DTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例6: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<RoleDTO> findAll(PageRequestByExample<RoleDTO> req) {
Example<Role> example = null;
Role role = toEntity(req.example);
if (role != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(Role_.roleName.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(role, matcher);
}
Page<Role> page;
if (example != null) {
page = roleRepository.findAll(example, req.toPageable());
} else {
page = roleRepository.findAll(req.toPageable());
}
List<RoleDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例7: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<PassportDTO> findAll(PageRequestByExample<PassportDTO> req) {
Example<Passport> example = null;
Passport passport = toEntity(req.example);
if (passport != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(Passport_.passportNumber.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(passport, matcher);
}
Page<Passport> page;
if (example != null) {
page = passportRepository.findAll(example, req.toPageable());
} else {
page = passportRepository.findAll(req.toPageable());
}
List<PassportDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例8: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<UseCase3DTO> findAll(PageRequestByExample<UseCase3DTO> req) {
Example<UseCase3> example = null;
UseCase3 useCase3 = toEntity(req.example);
if (useCase3 != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(UseCase3_.dummy.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(useCase3, matcher);
}
Page<UseCase3> page;
if (example != null) {
page = useCase3Repository.findAll(example, req.toPageable());
} else {
page = useCase3Repository.findAll(req.toPageable());
}
List<UseCase3DTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例9: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<UserDTO> findAll(PageRequestByExample<UserDTO> req) {
Example<User> example = null;
User user = toEntity(req.example);
if (user != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(User_.login.getName(), match -> match.ignoreCase().startsWith())
.withMatcher(User_.email.getName(), match -> match.ignoreCase().startsWith())
.withMatcher(User_.firstName.getName(), match -> match.ignoreCase().startsWith())
.withMatcher(User_.lastName.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(user, matcher);
}
Page<User> page;
if (example != null) {
page = userRepository.findAll(example, req.toPageable());
} else {
page = userRepository.findAll(req.toPageable());
}
List<UserDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例10: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<AuthorDTO> findAll(PageRequestByExample<AuthorDTO> req) {
Example<Author> example = null;
Author author = toEntity(req.example);
if (author != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(Author_.lastName.getName(), match -> match.ignoreCase().startsWith())
.withMatcher(Author_.firstName.getName(), match -> match.ignoreCase().startsWith())
.withMatcher(Author_.email.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(author, matcher);
}
Page<Author> page;
if (example != null) {
page = authorRepository.findAll(example, req.toPageable());
} else {
page = authorRepository.findAll(req.toPageable());
}
List<AuthorDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例11: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<ProjectDTO> findAll(PageRequestByExample<ProjectDTO> req) {
Example<Project> example = null;
Project project = toEntity(req.example);
if (project != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(Project_.name.getName(), match -> match.ignoreCase().startsWith())
.withMatcher(Project_.url.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(project, matcher);
}
Page<Project> page;
if (example != null) {
page = projectRepository.findAll(example, req.toPageable());
} else {
page = projectRepository.findAll(req.toPageable());
}
List<ProjectDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例12: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<UseCase2DTO> findAll(PageRequestByExample<UseCase2DTO> req) {
Example<UseCase2> example = null;
UseCase2 useCase2 = toEntity(req.example);
if (useCase2 != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(UseCase2_.dummy.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(useCase2, matcher);
}
Page<UseCase2> page;
if (example != null) {
page = useCase2Repository.findAll(example, req.toPageable());
} else {
page = useCase2Repository.findAll(req.toPageable());
}
List<UseCase2DTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例13: findAll
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Transactional(readOnly = true)
public PageResponse<BookDTO> findAll(PageRequestByExample<BookDTO> req) {
Example<Book> example = null;
Book book = toEntity(req.example);
if (book != null) {
ExampleMatcher matcher = ExampleMatcher.matching() //
.withMatcher(Book_.title.getName(), match -> match.ignoreCase().startsWith())
.withMatcher(Book_.summary.getName(), match -> match.ignoreCase().startsWith());
example = Example.of(book, matcher);
}
Page<Book> page;
if (example != null) {
page = bookRepository.findAll(example, req.toPageable());
} else {
page = bookRepository.findAll(req.toPageable());
}
List<BookDTO> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
}
示例14: testMultiple
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Test
public void testMultiple() {
// tag::example-flux[]
Employee e = new Employee();
e.setLastName("baggins"); // Lowercase lastName
ExampleMatcher matcher = ExampleMatcher.matching()
.withIgnoreCase()
.withMatcher("lastName", startsWith())
.withIncludeNullValues();
Example<Employee> example = Example.of(e, matcher);
// end::example-flux[]
// tag::query-flux[]
Flux<Employee> multipleEmployees = repository.findAll(example);
// end::query-flux[]
StepVerifier.create(multipleEmployees.collectList())
.expectNextMatches(employees -> {
assertThat(employees).hasSize(2);
assertThat(employees).extracting("firstName")
.contains("Frodo", "Bilbo");
return true;
})
.expectComplete()
.verify();
}
示例15: testMultipleWithTemplate
import org.springframework.data.domain.ExampleMatcher; //导入依赖的package包/类
@Test
public void testMultipleWithTemplate() {
// tag::flux-template[]
Employee e = new Employee();
e.setLastName("baggins"); // Lowercase lastName
ExampleMatcher matcher = ExampleMatcher.matching()
.withIgnoreCase()
.withMatcher("lastName", startsWith())
.withIncludeNullValues();
Example<Employee> example = Example.of(e, matcher);
Flux<Employee> multipleEmployees = operations.find(
new Query(byExample(example)), Employee.class);
// end::flux-template[]
StepVerifier.create(multipleEmployees.collectList())
.expectNextMatches(employees -> {
assertThat(employees).hasSize(2);
assertThat(employees).extracting("firstName")
.contains("Frodo", "Bilbo");
return true;
})
.expectComplete()
.verify();
}