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);

猜你喜欢

转载自www.cnblogs.com/JaminYe/p/13388015.html