条件构造器之AbstractWrapper实例

官方文档:https://mp.baomidou.com/guide/wrapper.html#abstractwrapper

总觉得直接看例子比看规则语句更快的理解和记忆,特此整合如下(分段纯属为了好对比)

  • allEq({id:1,name:"老王",age:null})---> where id = 1 and name = '老王' and age is null
  • allEq({id:1,name:"老王",age:null}, false)--->id = 1 and name = '老王'//忽略value为null的值
  • eq("name", "老王")---> where name = '老王'
  • ne("name", "老王")--->where name <> '老王'
  • gt("age", 18)---> where age > 18

  where...

  • ge("age", 18)--->age >= 18
  • lt("age", 18)--->age < 18
  • le("age", 18)--->age <= 18
  • between("age", 18, 30)--->age between 18 and 30
  • notBetween("age", 18, 30)--->age not between 18 and 30

 

  • like("name", "王")--->name like '%王%'
  • notLike("name", "王")--->name not like '%王%'
  • likeLeft("name", "王")--->name like '%王'
  • likeRight("name", "王")--->name like '王%'
  • isNull("name")--->name is null
  • isNotNull("name")--->name is not null

 

  • in("age",{1,2,3})--->age in (1,2,3)
  • in("age", 1, 2, 3)--->age in (1,2,3)
  • notIn("age",{1,2,3})--->age not in (1,2,3)
  • notIn("age", 1, 2, 3)--->age not in (1,2,3)
  • 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("age", "1,2,3,4,5,6")--->age not in (1,2,3,4,5,6)

 

  • groupBy("id", "name")--->group by id,name
  • orderByAsc("id", "name")--->order by id ASC,name ASC
  • orderByDesc("id", "name")--->order by id DESC,name DESC
  • orderBy(true, true, "id", "name")--->order by id ASC,name ASC
  • having("sum(age) > 10")--->having sum(age) > 10
  •  
  • eq("id",1).or().eq("name","老王")--->id = 1 or name = '老王'
  • or(i -> i.eq("name", "李白").ne("status", "活着"))--->or (name = '李白' and status <> '活着')
  • and(i -> i.eq("name", "李白").ne("status", "活着"))--->and (name = '李白' and status <> '活着')
  • nested(i -> i.eq("name", "李白").ne("status", "活着"))--->(name = '李白' and status <> '活着')
  •  
  • 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("limit 1")
  • exists("select id from table where age = 1")--->exists (select id from table where age = 1)
  • notExists("select id from table where age = 1")--->not exists (select id from table where age = 1)
  •  

你可能感兴趣的:(MyBatis-Plus)