1

background

The project uses mybatis-plus, it needs to traverse a grid array and associate it with or , but the other conditions outside the array are and , similar to

select 1 from t where  a = 1 and (b like '%2' or b = '%3' or b = '%4')

solution

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

noname
314 声望49 粉丝

一只菜狗