1.函数名及用法
//查询学生
QueryWrapper<Student> queryWrapper = new QueryWrapper();
函数 | 说明 | 举例 |
---|---|---|
eq | equals等于(=) | queryWrapper.lambda().eq(Student::getName,“老王”); |
ne | not equals不等于(<>) | queryWrapper.lambda().ne(Student::getName,“老王”); |
gt | greater than大于(>) | queryWrapper.lambda().gt(Student::getAge,26); |
ge | greater or equals大于等于(>=) | queryWrapper.lambda().ge(Student::getAge,26); |
lt | less than小于(<) | queryWrapper.lambda().lt(Student::getAge,26); |
le | less or equals小于等于(<=) | queryWrapper.lambda().le(Student::getAge,26); |
between | between a and b | queryWrapper.lambda().between(Student::getAge,26,30); |
notBetween | not between a and b | queryWrapper.lambda().notBetween(Student::getAge,26,30); |
like | like ‘%值%’ | queryWrapper.lambda().like(Student::getName,“老王”); |
notLike | not like ‘%值%’ | queryWrapper.lambda().notLike(Student::getName,“老王”); |
likeLeft | like ‘%值’ | queryWrapper.lambda().likeLeft(Student::getName,“老王”); |
likeRight | like ‘值%’ | queryWrapper.lambda().likeRight(Student::getName,“老王”); |
isNull | 字段 is null | queryWrapper.lambda().isNull(Student::getName); |
isNotNull | 字段 is not null | queryWrapper.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); |
groupBy | group by 字段a,字段b | queryWrapper.lambda().groupBy(Student::getId,Student::getName); |
orderBy | order by 字段a,字段b | queryWrapper.lambda().orderBy(Student::getId,Student::getName); |
orderByAsc | order by 字段a,字段b asc | queryWrapper.lambda().orderByAsc(Student::getId,Student::getName); |
orderByDesc | order by 字段a,字段b desc | queryWrapper.lambda().orderByDesc(Student::getId,Student::getName); |
having | having (sql语句) | queryWrapper.lambda().having(“sum(age) > {0}”, 122);//having sum(age) > 22; |
or | or拼接 | queryWrapper.lambda().eq(Student::getName,“老王”).or().eq(Student::getName,“老李”);// and (name =’老王’ or name = ‘老李’); |
and | and嵌套 | queryWrapper.lambda().and(obj ->obj.eq(TemplateEntity::getName, “老王”).or().like(TemplateEntity::getName, ‘王’));//and (name = ‘老王’ or name like ‘%王%’); |
apply | 拼接sql | queryWrapper.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或者OR | queryWrapper.lambda().nested(obj -> obj.eq(TemplateEntity::getName, “老王”).ne(TemplateEntity::getAge, 26));//and name = ‘老王’ and age != 26; |
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/92381.html