开发中使用LambdaQueryChainWrapper时涉及到or()链接时,如下代码
new LambdaQueryChainWrapper<>(bybFileMapper) .eq(BybFile::getByb00, bcqFile.getBcq00()) .eq(BybFile::getByb05, bcqFile.getBcq01()) .likeRight(BybFile::getByb01, "IYQ") .eq(BybFile::getByb08, plant.toUpperCase()).or().eq(BybFile::getByb08, plant.toUpperCase()).one();
解析到的SQL为:
SELECT BYB01,BYB02,BYB03,BYB04,BYB05,BYB06,BYB07,BYB00,BYB08,BYB09,BYB10,BYB11,BYB12 FROM WEBCUS.BYB_FILE WHERE (BYB00 = ? AND BYB05 = ? AND BYB01 LIKE ? AND BYB08 = ? OR BYB08 = ?)
导致SQL执行结果不符合预期。
解决方法一:
new LambdaQueryChainWrapper<>(bybFileMapper) .eq(BybFile::getByb00, bcqFile.getBcq00()) .eq(BybFile::getByb05, bcqFile.getBcq01()) .likeRight(BybFile::getByb01, "IYQ") .eq(BybFile::getByb08, plant.toUpperCase()).or().eq(BybFile::getByb08, plant.toUpperCase()) .eq(BybFile::getByb00, bcqFile.getBcq00()) .eq(BybFile::getByb05, bcqFile.getBcq01()) .likeRigh