Detailed explanation of mybatisPlus condition parameters

Detailed explanation of mybatis-plus official website: https://mp.baomidou.com/guide/wrapper.html#between

eq

  • Equal to =

  • Example:  eq("name", "老王")--->name = '老王'

allEq

  • All eq (or individual isNull)
  • Example 1:  allEq({id:1,name:"老王",age:null})--->id = 1 and name = '老王' and age is null
  • Example 2:  allEq({id:1,name:"老王",age:null}, false)--->id = 1 and name = '老王'

born

  • Not equal to <>
  • Example:  ne("name", "老王")--->name <> '老王'

gt

  • Greater than>
  • Example:  gt("age", 18)--->age > 18

give

  • Greater than or equal to >=
  • Example:  ge("age", 18)--->age >= 18

lt

  • Less than
  • Example:  lt("age", 18)--->age < 18

the

  • Less than or equal to <=
  • Example:  le("age", 18)--->age <= 18

between

  • BETWEEN value 1 AND value 2
  • Example:  between("age", 18, 30)--->age between 18 and 30

notBetween

  • NOT BETWEEN value 1 AND value 2
  • Example:  notBetween("age", 18, 30)--->age not between 18 and 30

like

  • LIKE'%value%'
  • Example:  like("name", "王")--->name like '%王%'

notLike

  • NOT LIKE '%值%'
  • Example:  notLike("name", "王")--->name not like '%王%'

likeLeft

  • LIKE'% value'
  • Example:  likeLeft("name", "王")--->name like '%王'

likeRight

  • LIKE'value%'
  • Example:  likeRight("name", "王")--->name like '王%'

isNull

  • Field IS NULL
  • Example:  isNull("name")--->name is null

isNotNull

  • Field IS NOT NULL
  • Example:  isNotNull("name")--->name is not null

in

  • 字段 IN (value.get(0), value.get(1), ...)
  • Example:  in("age",{1,2,3})--->age in (1,2,3)

notIn

  • 字段 NOT IN (value.get(0), value.get(1), ...)
  • Example:  notIn("age",{1,2,3})--->age not in (1,2,3)

inSql

  • Field IN (sql statement)
  • Example:  inSql("age", "1,2,3,4,5,6")--->age in (1,2,3,4,5,6)
  • Example:  inSql("id", "select id from table where id < 3")--->id in (select id from table where id < 3)

notInSql

  • Field NOT IN (sql statement)
  • Example:  notInSql("age", "1,2,3,4,5,6")--->age not in (1,2,3,4,5,6)
  • Example:  notInSql("id", "select id from table where id < 3")--->id not in (select id from table where id < 3)

groupBy

  • Grouping: GROUP BY field, ...
  • Example:  groupBy("id", "name")--->group by id,name

orderByAsc

  • Sort: ORDER BY field, ... ASC
  • Example:  orderByAsc("id", "name")--->order by id ASC,name ASC

orderByDesc

  • Sort: ORDER BY field, ... DESC
  • Example:  orderByDesc("id", "name")--->order by id DESC,name DESC

orderBy

  • Sorting: ORDER BY field, ...
  • Example:  orderBy(true, true, "id", "name")--->order by id ASC,name ASC

having

  • HAVING (sql statement)
  • Example:  having("sum(age) > 10")--->having sum(age) > 10
  • Example:  having("sum(age) > {0}", 11)--->having sum(age) > 11

func

  • func method (mainly convenient to call different methods in the presence of if...else can be chained continuously)
  • Example: func(i -> if(true) {i.eq("id", 1)} else {i.ne("id", 1)})

or

  • Splicing OR
  • eq("id",1).or().eq("name","老王")--->id = 1 or name = '老王'
  • 注意点:Active call ormeans that the next method is not andconnected! (If oryou don't call it, the default is to use the andconnection)
  • OR nesting
  • Example:  or(i -> i.eq("name", "李白").ne("status", "活着"))--->or (name = '李白' and status <> '活着')

and

  • AND nested
  • Example:  and(i -> i.eq("name", "李白").ne("status", "活着"))--->and (name = '李白' and status <> '活着')

nested

  • Normal nesting without AND or OR
  • Example:  nested(i -> i.eq("name", "李白").ne("status", "活着"))--->(name = '李白' and status <> '活着')

apply

  • Splicing sql
  • Note: This method can be used for database functions, and the dynamic input parameters paramscorrespond to the previous applySqlinternal {index}parts. This way there will be no risk of SQL injection, and vice versa!
  • Example:  apply("id = 1")--->id = 1
  • Example:  apply("date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")--->date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")
  • Example:  apply("date_format(dateColumn,'%Y-%m-%d') = {0}", "2008-08-08")--->date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")

last

  • Ignore the optimization rules directly spliced ​​to the end of sql
  • Note: You can only call it once, and multiple calls are subject to the risk of SQL injection. Please use it with caution
  • Example: last("limit 1")

exists

  • Splicing EXISTS (sql statement)
  • Example:  exists("select id from table where age = 1")--->exists (select id from table where age = 1)

notExists

  • Splicing NOT EXISTS (sql statement)
  • Example:  notExists("select id from table where age = 1")--->not exists (select id from table where age = 1)

 

 

Guess you like

Origin blog.csdn.net/qq_36138652/article/details/114635750