02-myBatisPlus的wrapper接口的使用
02-myBatisPlus的wrapper接口的使用。
1.直接先上硬菜
序号 | 函数名 | 说明 | 说明/例子 |
---|---|---|---|
1 | eq | 等于= | eq(“name”,”二狗子”) ==> where name = ‘二狗子‘ |
2 | ne | 不等于 <> | ne(“name”,”二狗子”) ==> where name <> ‘二狗子‘ |
3 | gt | 大于 > | gt(“age”,18) ==> where age >18 |
4 | ge | 大于等于 >= | ge(“”age”,18) ==> where age >=18 |
5 | lt | 小于 < | lt(“age”,18″) ==> where age <18 |
6 | le | 小于等于 <= | le(“age”,18) ==> where age <=18 |
7 | between | between 值1 and值2 | between(“age”,18,30) ==> where age between 18 and 30 |
8 | notBetween | not between 值1 and值2 | not between(“age”,18,30) ==> where age not between 18 and 30 |
9 | like | like ‘%值%‘ | like(“name”,”二”) ==> where name like ‘%二%‘ |
10 | notLike | not like ‘%值%‘ | notLike(“name”,”二”) ==> where name not like ‘%二%‘ |
11 | likeLeft | like ‘%值‘ | likeLeft(“name”,”二”) ==> where name like ‘%二‘ |
12 | likeRight | like ‘值%‘ | likeRight(“name”,”二”) ==> where name like ‘二%‘ |
13 | isNull | 字段 is null | isNUll(”name“) ==> where name is null |
14 | isNotNull | 字段 is not null | isNotNull(“name”) ==> where name is not null |
15 | in | 字段 in ( v0,v1,v2…) | in(“age”,{1,2,3}) ==> where age in (1,2,3) |
16 | notIn | 字段 not in(v0,v1…) | notIn(“age”,{1,2,3}) ==> where age not in(1,2,3) |
17 | inSql | 字段 in ( sql语句) | inSql(“id”,”select id form user where age > 3″) ==> id in(select id form user where age > 3) |
18 | notInSql | 字段 not in ( sql语句) | notInSql(“id”,”select id form user where age > 3″) ==> id not in(select id form user where age > 3) |
19 | groupBy | 分组:group by | groupBy(“id”,”name”) ==> group by id,name |
20 | orderByAsc | 排序 :order by 正序 | orderByAsc(“id”,”name”) ==> order by id ASC,name ASC |
21 | orderByDesc | 排序 :order by 倒序 | orderByDesc(“id”,”name”) ==> order by id DESC,name DESC |
22 | orderBy | 排序:order by | orderBy(“id”,”name”) ==> order by id ASC,name ASC |
23 | having | having(sql语句) | having(“sum{age} > {0}”,11) ==> having sum(age) >11 |
24 | or | 拼接 or | 注意事项:主动调用or表示紧接着下一个方法不是用and连接!(不调用or则用and连接)eq(“id”,1).or().eq(“name”,”二狗子”) ==> id = 1 or name = ‘二狗子‘ |
25 | and | and嵌套 | and(mapper.eq(“id”,1).ne(“status”,”活着“))==> id = 1 and status <> ‘活着‘ |
26 | apply | 拼接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‘; |
27 | last | 无视优化规则直接拼接到sql的最后 | 注意事项:只能调用一次,多次调用以最后一次为准。有sql注入风险,需要谨慎使用。last(“limit 1”); |
28 | exists | 拼接 exists(sql语句) | exists(“select id from user where age = 1”) ==> exists(select id from user where age = 1); |
29 | notExists | 拼接 not exists(sql语句) | notExists(“select id from user where age = 1”) ==>not exists(select id from user where age = 1); |
30 | nested | 正常嵌套,不带and或or | nested(mapper.eq(“id”,1).ne(“status”,”活着“)) ==> (id = 1 and status <> ‘活着‘) |