Jpa创建筛选器自动忽略nul值进行搜索

Jpa创建筛选器自动忽略nul值进行搜索

//创建一个筛选器
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("code", ExampleMatcher.GenericPropertyMatchers.contains().startsWith()).withIgnoreNullValues().withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains());
Person person=new Person();
person.setCode(code);
person.setName(name);
Example<Person> example=Example.of(person,exampleMatcher);
List<Person> personList=personRepository.findAll(example);
posted @ 2020-07-27 22:24  JaminYe  阅读(444)  评论(0编辑  收藏  举报