mybatisplus高级查询方法
QueryWrapper 高级查询方法
1、常用
.eq ---- 等于 " = " 例: eq("name","老王")--->name ='老王’
.ne ---- 不等于 " != " 例: ne("name","老王")--->name <>'老王’
.gt ---- 大于 " > " 例: gt("age",18)--->age > 18
.ge ---- 大于等于 " >= " 例: ge("age",18)--->age >= 18
.lt ---- 小于 " < " 例: lt("age",18)--->age< 18
.le ---- 小于等于 " <= " 例: le("age",18)--->age <= 18
2、次之
.between ---- " between 值1 and 值2 " 例:between("age",18,30)--->age .between 18 and 30
.notBetween ---- " ontBetween 值1 and 值2 " 例: notBetween("age”,18,30)--->age .not between 18 and 30
.like ---- " like '%值%' " 例:like("name","王")--->name like'%王%'
.notLike ---- "Not Like '%值%'" 例:notLike("name","王")--->name not like'%王%
.likeLeft ---- " like '%值' " 例:likeLeft("name","王")--->name like'%王
.likeRight ---- " like '值%' " 例:likeRight("name","王")--->name like'王%
.isNull ---- " 字段 is null " 例:isNull("name")--->name is null
.isNotNull ---- "字段 is not null " 例:isNotNull("name")--->name is not null
.in ---- " 字段 in (v0,v1,...) " 例:in("age",{1,2,3])--->age in (1,2,3)
.notIn ---- " 字段 not in (v0,v1,...) " 例:notIn("age",1,2,3)--->age not in (1,2,3)
.inSql ---- IN( sql语句) inSql("id","select id from table where id < 3" ---- id 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)in
3、再次之
.groupBy分组 ---- GROUP BY 字段... 例:groupBy("id","name")--->group by id,name
.orderByAsc排序 ---- ORDER BY 字段,... ASC 例:orderByAsc("id","name")--->order by id ASC,name ASC
.orderByDesc排序 ---- ORDER BY 字段,... DESC 例:orderByDesc("id","name")--->order by id DESC,name DESC
.orderBy排序 ---- ORDER BY 字段,... --->order by id ASC.name ASC 例:orderBy(true,true,"id","name")
.having去重 ---- HAVING(sql语句) having("sum(age)>[0]",11)--->having sum(age) >11
.apply 拼接sq1 注意事项: 该方法可用于数据库函数动态入参的params对应前面sq1Having内部的 (index)部分。这样是不会有sql注入风险的,反之会有! 例: apy(~date_ format(dateColumn, '%-a-~) = {0]", *2008 -08- 08")--->date_ format (dateColumn,' %Y-Mm=-%d') = *2008 -08-08'’) 无视优化规则直接拼接到sq1的最后 注意事项: 只能调用一次,多次调用以最后-次为准有sql注入的风险,请谨慎使用 例: last("limit 1")
.last 无视优化规则直接拼接到sq1的最后
.exists 拼接EXISTS ( sq1语句) 例: exists(" select id from table where age = 1") -->exists (select id from table where age三1)
.notExists 拼接NOT EXISTS ( sq1语句) 例: notExists(" 'select id from table where age = 1") -->not exists (select id from table where age三1)
.nested 正常嵌套不带AND或者OR 正常嵌套不带AND或者OR 例: nested(i -> i.eq( "name"," 李白").ne(' 'status", ’'活着")) -->(name = '李白’and status. <>"活着’)
版权声明:本文为laughingcdp原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。