02-myBatisPlus的wrapper接口的使用

【02-myBatisPlus的wrapper接口的使用】临文乍了了,彻卷兀若无。这篇文章主要讲述02-myBatisPlus的wrapper接口的使用相关的知识,希望能为你提供帮助。
02-myBatisPlus的wrapper接口的使用。1.直接先上硬菜

序号函数名说明说明/例子
1eq等于=eq("name","二狗子") ==> wherename = \'二狗子\'
2ne不等于 < > ne("name","二狗子") ==> where name < > \'二狗子\'
3gt大于 > gt("age",18) ==> whereage > 18
4ge大于等于 > =ge(""age",18) ==> where age > =18
5lt小于 < lt("age",18") ==> where age < 18
6le小于等于 < =le("age",18) ==> whereage < =18
7betweenbetween 值1 and值2between("age",18,30) ==> where age between 18 and 30
8notBetweennot between 值1 and值2not between("age",18,30) ==> where age not between 18 and 30
9likelike \'%值%\'like("name","二") ==> where name like \'%二%\'
10notLikenot like \'%值%\'notLike("name","二") ==> where name not like \'%二%\'
11likeLeftlike \'%值\'likeLeft("name","二") ==> where name like \'%二\'
12likeRightlike \'值%\'likeRight("name","二") ==> where name like \'二%\'
13isNull字段 is nullisNUll(”name“) ==> wherename is null
14isNotNull字段 is not nullisNotNull("name") ==> where name is not null
15in字段 in ( v0,v1,v2...)in("age",{1,2,3}) ==> where age in (1,2,3)
16notIn字段 not in(v0,v1...)notIn("age",{1,2,3}) ==> where age not in(1,2,3)
17inSql字段 in ( sql语句)inSql("id","select id form user where age > 3") ==> id in(select id form user where age > 3)
18notInSql字段 not in ( sql语句)notInSql("id","select id form user where age > 3") ==> idnot in(select id form user where age > 3)
19groupBy分组:group bygroupBy("id","name") ==> group by id,name
20orderByAsc排序 :order by 正序orderByAsc("id","name") ==> order by id ASC,name ASC
21orderByDesc排序 :order by 倒序orderByDesc("id","name") ==> order by id DESC,name DESC
22orderBy排序:order byorderBy("id","name") ==> order by id ASC,name ASC
23havinghaving(sql语句)having("sum{age} > {0}",11) ==> having sum(age) > 11
24or拼接 or注意事项:主动调用or表示紧接着下一个方法不是用and连接!(不调用or则用and连接)eq("id",1).or().eq("name","二狗子") ==> id = 1 or name = \'二狗子\'
25andand嵌套and(mapper.eq("id",1).ne("status",”活着“))==> id = 1 and status < > \'活着\'
26apply拼接sql注意事项:该方法可用于数据库函数。动态入参的params对应前面sqlHaving{index}部分。这样是不会有sql注入风险的,反之则会有! apply("date_format(dateColumn,\'%Y-%m-%d\') = {0}","2020-10-24") ==> date_format(dateColumn,\'%Y-%m-%d\') = \'2020-10-24\';
27last无视优化规则直接拼接到sql的最后注意事项:只能调用一次,多次调用以最后一次为准。有sql注入风险,需要谨慎使用。last("limit 1");
28exists拼接 exists(sql语句)exists("select id from user where age = 1") ==> exists(select id from user where age = 1);
29notExists拼接 not exists(sql语句)notExists("select id from user where age = 1") ==> not exists(select id from user where age = 1);
30nested正常嵌套,不带and或ornested(mapper.eq("id",1).ne("status",”活着“)) ==> (id = 1 and status < > \'活着\')
2.wrapper家族的关系

02-myBatisPlus的wrapper接口的使用

文章图片




来自为知笔记(Wiz)


    推荐阅读