背景
專案使用mybatis-plus,需要遍歷一格陣列,用or
關聯起來,但是陣列外跟其他條件是and
,類似
select 1 from t where a = 1 and (b = 2 or b = 3 or b = 4)
解法
queryWrapper.and(qw -> {
for (int i = 0; i < values.length; i++) {
String val = values[i];
if (i == 0) {
qw.nested(w -> w.likeRight("b", val));
} else {
qw.or(w -> w.likeRight("b", val));
}
}
});