尝试使用examplematcher查询查找多个字段。在下面的课程中,我们有4个领域:
public class contact {
private String name;
private long phoneNumber; //primary
private String email;
private String organization;
}
现在举例来说,我想搜索与姓名和电子邮件领域和其他领域的要求是空的。结果应该是包含姓名和电子邮件请求的联系人列表。我的搜索请求获取未知数量的字段。
ExampleMatcher userExampleMatcher = ExampleMatcher.matchingAll()
.withNullHandler(ExampleMatcher.NullHandler.IGNORE);
Iterable<Contact> contacts = dao.findAll(Example.of(contactObject, userExampleMatcher));
此配置仅用于电话号码返回true结果,其他字段返回null。
1条答案
按热度按时间c7rzv4ha1#
如果
Contact
实体具有基本字段,那么它们的默认值将实际用于创建查询。如果不设置phonenumber,它将始终查找phonenumber=0
你可以替换
Primitive
字段Wrapper
领域:ExampleMatcher userExampleMatcher = ExampleMatcher.matchingAll()
.withIgnorePaths("phoneNumber").withIgnoreNullValues();