allEq |
params:key爲數據庫字段名,value爲字段值 , null2IsNull:爲true則在map的value爲null時調用 isNull 方法,爲false時則忽略value爲null的 |
例1 : allEq({id:1,name:“老王”,age:null})—>id = 1 and name = ‘老王’ and age is null例2 : allEq({id:1,name:“老王”,age:null}, false)—>id = 1 and name = ‘老王’ |
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 |
between |
BETWEEN 值1 AND 值2 |
between(“age”, 18, 30)—>age between 18 and 30 |
notBetween |
NOT BETWEEN 值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 '值%' |
ikeRight(“name”, “王”)—>name like ‘王%’’ |
isNull |
字段 IS NULL |
isNull(“name”)—>name is null’ |
isNotNull |
字段 IS NOT NULL |
例: isNotNull(“name”)—>name is not null# |
in |
字段 IN (value.get(0), value.get(1), ...) 或 字段 IN (v0, v1, ...)' |
in(“age”,{1,2,3})—>age in (1,2,3) 或 in(“age”, 1, 2, 3)—>age in (1,2,3) |
notIn |
字段 NOT IN (value.get(0), value.get(1), ...) 字段 NOT IN (v0, v1, ...) |
例: notIn(“age”,{1,2,3})—>age not in (1,2,3) notIn(“age”, 1, 2, 3)—>age not in (1,2,3) |
inSql |
字段 IN ( sql語句 ) |
例: inSql(“age”, “1,2,3,4,5,6”)—>age in (1,2,3,4,5,6)例: inSql(“id”, “select id from table where id < 3”)—>id in (select id from table where id < 3) |
notInSql |
字段 NOT IN ( sql語句 ) |
例: notInSql(“age”, “1,2,3,4,5,6”)—>age not in (1,2,3,4,5,6)例: notInSql(“id”, “select id from table where id < 3”)—>id not in (select id from table where id < 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 字段, ... |
例: orderBy(true, true, “id”, “name”)—>order by id ASC,name ASC |
having |
HAVING ( sql語句 ) |
例: having(“sum(age) > 10”)—>having sum(age) > 10 例: having(“sum(age) > {0}”, 11)—>having sum(age) > 11 |
or |
拼接 OR 注意事項: 主動調用or表示緊接着下一個方法不是用and連接!(不調用or則默認爲使用and連接) |
例: eq(“id”,1).or().eq(“name”,“老王”)—>id = 1 or name = ‘老王’ |
or |
OR 嵌套 |
例: or(i -> i.eq(“name”, “李白”).ne(“status”, “活着”))—>or (name = ‘李白’ and status <> ‘活着’) |
and |
AND 嵌套 |
例: and(i -> i.eq(“name”, “李白”).ne(“status”, “活着”))—>and (name = ‘李白’ and status <> ‘活着’) |
nested |
正常嵌套 不帶 AND 或者 OR |
例: nested(i -> i.eq(“name”, “李白”).ne(“status”, “活着”))—>(name = ‘李白’ and status <> ‘活着’) |
apply |
拼接 sql 注意事項:該方法可用於數據庫函數 動態入參的params對應前面applySql內部的{index}部分.這樣是不會有sql注入風險的,反之會有! |
例: apply(“id = 1”)—>id = 1例: apply(“date_format(dateColumn,’%Y-%m-%d’) = ‘2008-08-08’”)—>date_format(dateColumn,’%Y-%m-%d’) = ‘2008-08-08’")例: apply(“date_format(dateColumn,’%Y-%m-%d’) = {0}”, “2008-08-08”)—>date_format(dateColumn,’%Y-%m-%d’) = ‘2008-08-08’") |
last |
無視優化規則直接拼接到 sql 的最後 注意事項:只能調用一次,多次調用以最後一次爲準 有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) |