Person person = new Person();
person.setName("test");
Role role = new Role();
role.setName("经理");
person.setRole(role);
...
Example<Person> ex = Example.of(person); //动态查询
personRepository.findAll(ex);
personRepository.findAll(ex,pageable); //分页
Person person = new Person();
person.setName(name);
//默认匹配器:字符串采用精准查询,忽略大小写(文档说不忽略大小写,本人测试时发现是忽略大小写的)
ExampleMatcher matcher = ExampleMatcher.matching()
// .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配为:模糊查询
// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains()) //name字段模糊匹配
// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.startsWith()) //name字段开头模糊匹配
// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.endsWith()) //name字段结尾模糊匹配
// .withIgnorePaths("id","phone"); //忽略id,phone字段
Example<Person> ex = Example.of(person,matcher); //动态查询
return personRepository.findAll(ex);
retuen personRepository.fiadAll(ex,pageable) //分页