背景
我的项目应用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)); } }});