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) //分頁