Mybatis Plus的Sql语句加入and
在开发中,曾遇到一个bug,sql语句中没加上括号会导致查询出来的结果错误
QueryWrapper<Label> queryWrapper = new QueryWrapper();
StringBuffer stringBuffer = new StringBuffer();
StringBuffer append = stringBuffer.append(",").append(label.getOrgId()).append(",");
String s = new String(append);
queryWrapper.lambda().eq(Label::getStatus, 1);
queryWrapper.lambda().and(wrapper ->
wrapper.like(Label::getOrgId, s).or().eq(Label::getOrgId, Label.SELECT_ALL)
);
这样子查出的语句是
select * from XXX
where status = 1 and (orgId like '%xxx%'or orgid = xxx)