QueryWrapper常用方法

QueryWrapper概述:

        也称条件构造器,继承自AbstractWrapper,自身的内部属性entity,也用于生成where条件及LambdaQueryWapper,可以通过new QueryWrapper().lambda()方法获取

QueryWrapper<Employee> wrapper = new QueryWrapper<>()

QueryWrapper常用方法

函数名说明例子
eq等于 =eq("name","海绵宝宝")  →  name="海绵宝宝"
ne不等于 <>ne("name","海绵宝宝")  →  name<>"海绵宝宝"

gt

大于 >gt("age","18")   →  age>18
ge大于等于 >=ge("age","18")  →  age>=18
le小于等于 <=le("age","18")  →  age<=18
lt小于 <lt("age","18")  →  age<18
betweenBETWEEN 值1 and 值2between("age",18,30)  →  age between 18 and 30
notBetweenNOT BETWEEN 值1 and 值2between("age",18,30)  →  age not between 18 and 30
likeLIKE '%值%'like("name","海")  →  name like "%海%"
notLikeNOT LIKE '%值%'not like("name","海")  →  name like "%海%"
likeLeftLIKE '%值'leftLlike("name","海")  →  name like "%海"
likeRightLIKE '值%'rightLlike("name","海")  →  name like "海%"
isNull字段 IS NULLisNull("name")  →  name is null
isNotNull字段 IS NOT NULLis Not Null("name")  →  name is not null
in字段 IN(v0,v1,v2,...)in("age",{1,2,3})  →  age in (1,2,3)
notIn字段 NOT IN(v0,v1,v2,...)notIn("age",{1,2,3})  →  age not in (1,2,3)

inSql

字段 IN(sql语句)

inSql("id","select id from table where id<3") 

→  age in(select id from table where id<3) 

notInSql字段 NOT IN(sql语句)

notInSql("id","select id from table where id<3") 

→  age not in(select id from table where id<3) 

groupBy分组:groupBygroupBy("id","name")  →  group by id,name
orderByAsc正序排序orderByAsc("id","name")  →  order by id Asc,name Asc
orderByDesc倒序排序orderByDesc("id","name") → order by id Desc,name Desc
orderBy排序  :ODER BY 字段orderBy(true,true,"id","name")→ order by id Asc,name Asc
havingHAVING(sql语句)having("sum(age) > {0}",11) →  having sum(age) >11
or拼接 OR

eq("id",1).or().eq("name","派大星")

→  id=1 or name="派大星"

andAND 嵌套用于嵌套
apply拼接 sql用于数据库函数,一般having很少用
last无视化规则直接拼接到sql的最后只能调用一次  last("limit 1")
exists拼接EXISTS(sql语句)

exists("select id from table where age = 1")

→exists("select id from table where age = 1")

notExists拼接NOT EXISTS(sql语句)

notExists("select id from table where age = 1")

→not exists("select id from table where age = 1")


版权声明:本文为weixin_62460384原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。