【java】mybatis-plus lambda表达式符号总结

29 篇文章 0 订阅
1.函数名及用法
//查询学生
QueryWrapper<Student> queryWrapper = new QueryWrapper();
函数说明举例
eqequals等于(=)queryWrapper.lambda().eq(Student::getName,“老王”);
nenot equals不等于(<>)queryWrapper.lambda().ne(Student::getName,“老王”);
gtgreater than大于(>)queryWrapper.lambda().gt(Student::getAge,26);
gegreater or equals大于等于(>=)queryWrapper.lambda().ge(Student::getAge,26);
ltless than小于(<)queryWrapper.lambda().lt(Student::getAge,26);
leless or equals小于等于(<=)queryWrapper.lambda().le(Student::getAge,26);
betweenbetween a and bqueryWrapper.lambda().between(Student::getAge,26,30);
notBetweennot between a and bqueryWrapper.lambda().notBetween(Student::getAge,26,30);
likelike ‘%值%’queryWrapper.lambda().like(Student::getName,“老王”);
notLikenot like ‘%值%’queryWrapper.lambda().notLike(Student::getName,“老王”);
likeLeftlike ‘%值’queryWrapper.lambda().likeLeft(Student::getName,“老王”);
likeRightlike ‘值%’queryWrapper.lambda().likeRight(Student::getName,“老王”);
isNull字段 is nullqueryWrapper.lambda().isNull(Student::getName);
isNotNull字段 is not nullqueryWrapper.lambda().isNotNull(Student::getName);
in字段 in (a,b,c)queryWrapper.lambda().in(Student::getId, idList);//注意判断idList不为空
notIn字段 not in (a,b,c)queryWrapper.lambda().notIn(Student::getId, idList);//注意判断idList不为空
inSql字段 in (sql语句)queryWrapper.lambda().inSql(Student::getId,“select id from student where is_deleted = 0”);//id in (select id from student where is_deleted = 0);
notInSql字段 not in (sql语句)queryWrapper.lambda().notInSql(Student::getId,“select id from student where is_deleted = 0”);//id not in (select id from student where is_deleted = 0);
groupBygroup by 字段a,字段bqueryWrapper.lambda().groupBy(Student::getId,Student::getName);
orderByorder by 字段a,字段bqueryWrapper.lambda().orderBy(Student::getId,Student::getName);
orderByAscorder by 字段a,字段b ascqueryWrapper.lambda().orderByAsc(Student::getId,Student::getName);
orderByDescorder by 字段a,字段b descqueryWrapper.lambda().orderByDesc(Student::getId,Student::getName);
havinghaving (sql语句)queryWrapper.lambda().having(“sum(age) > {0}”, 122);//having sum(age) > 22;
oror拼接queryWrapper.lambda().eq(Student::getName,“老王”).or().eq(Student::getName,“老李”);// and name ='老王’ or name = ‘老李’;
andand嵌套queryWrapper.lambda().and(obj ->obj.eq(TemplateEntity::getName, “老王”).or().like(TemplateEntity::getName, ‘王’));//and (name = ‘老王’ or name like ‘%王%’);
apply拼接sqlqueryWrapper.lambda().apply(" and date_format(update_time, ‘%Y-%m-%d’) ={0}",“2021-10-16”);//and date_format(update_time, ‘%Y-%m-%d’) = ‘2021-10-16’; 直接传参会有sql注入风险
last无视优化规则直接拼接到sql最后queryWrapper.lambda().last(" limit 1,10");// limit 1,10; 只能调用一次,多次调用以最后一次为准,有sql注入的风险,请谨慎使用
exists拼接exists语句queryWrapper.lambda().exists(" select id from student where name = '老王‘’");// exists (select id from student where name = ‘老王’);
notExists拼接not exists语句queryWrapper.lambda().notExists(" select id from student where name = '老王‘’");// not exists (select id from student where name = ‘老王’);
nested正常嵌套不带AND或者ORqueryWrapper.lambda().nested(obj -> obj.eq(TemplateEntity::getName, “老王”).ne(TemplateEntity::getAge, 26));//and name = ‘老王’ and age != 26;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王佑辉

老板,赏点吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值