在查询过程中 经常会有类似如下查询
A='123' and (B='456' or C='789' or D='110')
lambdaWrapper.eq("A","123");
lambdaWrapper.and(wrapper->{
wrapper.or().eq("B","456");
wrapper.or().eq("C","789");
wrapper.or().eq("D","110");
})
项目中应用,根据集合拼接查询条件
lambdaWrapper.and(wrapper -> {
for (DataAuthorityDO dataAuthorityDO : list) {
if (dataAuthorityDO.getIsContainChild().equals(DataAuthorityStatus.IS_CONTAIN_CHILD.code())) {
wrapper.or().likeRight(OrgBase::getFullPath, dataAuthorityDO.getFullPath());
} else {
wrapper.or().eq(OrgBase::getId, dataAuthorityDO.getOrgId());
}
}
return wrapper;
});
// A or (B and C)
.eq("a", "A").or(i -> i.eq("b", "B").eq("c", "C"));
// A or (B or C)
.eq("a", "A").or(i -> i.eq("b", "B").or().eq("c", "C"));
// A and (B and C)
.eq("a", "A").and(i -> i.eq("b", "B").eq("c", "C"));
// A and (B or C)
.eq("a", "A").and(i -> i.eq("b", "B").or().eq("c", "C"));