需求如下: 如果:如果设置值的时候,值为空则不执行查询语句 代码: 当isDeleted为null的时候 @Test void method() { Integer isDeleted = null; La
需求如下:
如果:如果设置值的时候,值为空则不执行查询语句
代码:
当isDeleted为null的时候
@Test void method() { Integer isDeleted = null; LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(!ObjectUtils.isEmpty(isDeleted),DeviceBrand::getIsDeleted,isDeleted); log.info(String.valueOf(queryWrapper)); }
调试结果:
此时expression里面的nORMal size == 0
当isDeleted为1的时候
@Test void method() { Integer isDeleted = 1; LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(!ObjectUtils.isEmpty(isDeleted),DeviceBrand::getIsDeleted,isDeleted); log.info(String.valueOf(queryWrapper)); }
此时expression里面的normal size == 3
protected Children addCondition(boolean condition, R column, SqlKeyword sqlKeyword, Object val) { return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), sqlKeyword, () -> formatParam(null, val))); } protected final Children maybeDo(boolean condition, DoSomething something) { if (condition) { something.doIt(); } return typedThis; }
如果condition为 true则执行右边的函数,为false则反之
来源地址:https://blog.csdn.net/qq_43375661/article/details/126877725
--结束END--
本文标题: mybatis-plus LambdaQueryWrapper之判断值是否存在,存在则加入查询,反之亦然
本文链接: https://lsjlt.com/news/376518.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0