最近,同事新增一个项目使用springboot+mybatis-plus的使用,对于queryWrapper,updateWrapper这一系列的构造器有些迷糊,为了更好的说明使用的方式 我在这篇博客中简单简述一下。

1.构造器的关系

 2.函数相关说明

函数名说明例子
eq等于==例:eq("age",10)---> age = 10
ne不等于 <>例:ne("age",10)---> age <> 10
gt大于 >例:gt("age",10)---> age > 10
ge大于等于  >=例:ge("age",10)---> age >= 10
lt小于 <例:lt("age",10)---> age < 10
le小于等于 <=例:le("age",10)---> age < = 10
between between  *  and  *例:between("age",10,20)---> age between 10 and 20
notBetweenNot  between  *  and  *例:notBetween("age",10,20)---> age not between 10 and 20
likelike '%XX%'例:like("name","徐") ---> name like "%徐%"
notLikeNot like '%XX%'例:notLike("name","徐") ---> name not like "%徐%"
likeLeftlike '%XX%'例:likeLeft("name","徐") ---> name like "%徐"
likeRightlike '%XX%'例:likeRight("name","徐") ---> name like "徐%"
isNull字段 is null例:isNull("name") --->name  is null
isNotNull字段 is  not null例:isNotNull("name") --->name  is not  null
in字段 in (XX,xx,x)例:in ("age",{1,2,3})---> age in (1,2,3)
notIn字段  not in (XX,xx,x)例:notIn("age",{1,2,3})---> age not  in (1,2,3)
inSql字段  in (sql 语句)

例:inSql("id", select id from student where id <3 ) --->

id in ( select id from student where id <3)

notInSql字段 not in (sql 语句)例:notInSql("id", select id from student where id <3 ) --->

id not in ( select id from student where id <3)

groupBy分组:group by例:groupBy("id","name") --->group By id ,name
orderByAsc排序:order by 字段 ,.. Asc例:orderByAsc("id","name") --->order By id ,name    Asc
orderByDesc排序:order by 字段 ,.. desc例:orderByDesc("id","name") --->order By id ,name    desc
orderBy排序:order by 字段 ,..例:orderBy(true,true,"id","name") --->order By id asc , name    sc
havingHAVING(sql 语句)例:having("sum(age) > {0}",11) ---> -having sum(age) > 11
or拼接 or

例:

eq("age",10).or.eq("age",11) ---> age= 10  or age = 11

 

and and 嵌套例:
last无视优化规则直接拼接到 sql 最后例:
exists拼接 exists (sql 语句)例:
notexists拼接 not exists (sql 语句)例:
nested正常嵌套 不带 and  或者 or例:
apply拼接 sql

例:apply("date_format(create_time,'%Y-%m-%d')={0}, "2020-01-17")--------->

date_format(create_time,'%Y-%m-%d')="2020-01-17"

   
   

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐