类 AbstractWrapper<T,​R,​Children extends AbstractWrapper<T,​R,​Children>>

java.lang.Object
com.baomidou.mybatisplus.core.conditions.Wrapper<T>
com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,​R,​Children>
所有已实现的接口:
Compare<Children,​R>, Func<Children,​R>, Join<Children>, Nested<Children,​Children>, ISqlSegment, Serializable
直接已知子类:
AbstractLambdaWrapper, QueryWrapper, UpdateWrapper

public abstract class AbstractWrapper<T,​R,​Children extends AbstractWrapper<T,​R,​Children>>
extends Wrapper<T>
implements Compare<Children,​R>, Nested<Children,​Children>, Join<Children>, Func<Children,​R>
查询条件封装
从以下版本开始:
2017-05-26
作者:
hubin miemie HCL
另请参阅:
序列化表格
  • 字段详细资料

  • 构造器详细资料

    • AbstractWrapper

      public AbstractWrapper()
  • 方法详细资料

    • getEntity

      public T getEntity()
      从类复制的说明: Wrapper
      实体对象(子类实现)
      指定者:
      getEntity 在类中 Wrapper<T>
      返回:
      泛型 T
    • setEntity

      public Children setEntity​(T entity)
    • getEntityClass

      public Class<T> getEntityClass()
    • setEntityClass

      public Children setEntityClass​(Class<T> entityClass)
    • allEq

      public <V> Children allEq​(boolean condition, Map<R,​V> params, boolean null2IsNull)
      从接口复制的说明: Compare
      map 所有非空属性等于 =
      指定者:
      allEq 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      params - map 类型的参数, key 是字段名, value 是字段值
      null2IsNull - 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段\
      返回:
      children
    • allEq

      public <V> Children allEq​(boolean condition, BiPredicate<R,​V> filter, Map<R,​V> params, boolean null2IsNull)
      从接口复制的说明: Compare
      字段过滤接口,传入多参数时允许对参数进行过滤
      指定者:
      allEq 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      filter - 返回 true 来允许字段传入比对条件中
      params - map 类型的参数, key 是字段名, value 是字段值
      null2IsNull - 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段
      返回:
      children
    • eq

      public Children eq​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      等于 =
      指定者:
      eq 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • ne

      public Children ne​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      不等于 <>
      指定者:
      ne 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • gt

      public Children gt​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      大于 >
      指定者:
      gt 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • ge

      public Children ge​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      大于等于 >=
      指定者:
      ge 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • lt

      public Children lt​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      小于 <
      指定者:
      lt 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • le

      public Children le​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      小于等于 <=
      指定者:
      le 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • like

      public Children like​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      LIKE '%值%'
      指定者:
      like 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • notLike

      public Children notLike​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      NOT LIKE '%值%'
      指定者:
      notLike 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • likeLeft

      public Children likeLeft​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      LIKE '%值'
      指定者:
      likeLeft 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • likeRight

      public Children likeRight​(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      LIKE '值%'
      指定者:
      likeRight 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val - 值
      返回:
      children
    • between

      public Children between​(boolean condition, R column, Object val1, Object val2)
      从接口复制的说明: Compare
      BETWEEN 值1 AND 值2
      指定者:
      between 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val1 - 值1
      val2 - 值2
      返回:
      children
    • notBetween

      public Children notBetween​(boolean condition, R column, Object val1, Object val2)
      从接口复制的说明: Compare
      NOT BETWEEN 值1 AND 值2
      指定者:
      notBetween 在接口中 Compare<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      val1 - 值1
      val2 - 值2
      返回:
      children
    • and

      public Children and​(boolean condition, Consumer<Children> consumer)
      从接口复制的说明: Nested
      AND 嵌套

      例: and(i -> i.eq("name", "李白").ne("status", "活着"))

      指定者:
      and 在接口中 Nested<T,​R>
      参数:
      condition - 执行条件
      consumer - 消费函数
      返回:
      children
    • or

      public Children or​(boolean condition, Consumer<Children> consumer)
      从接口复制的说明: Nested
      OR 嵌套

      例: or(i -> i.eq("name", "李白").ne("status", "活着"))

      指定者:
      or 在接口中 Nested<T,​R>
      参数:
      condition - 执行条件
      consumer - 消费函数
      返回:
      children
    • nested

      public Children nested​(boolean condition, Consumer<Children> consumer)
      从接口复制的说明: Nested
      正常嵌套 不带 AND 或者 OR

      例: nested(i -> i.eq("name", "李白").ne("status", "活着"))

      指定者:
      nested 在接口中 Nested<T,​R>
      参数:
      condition - 执行条件
      consumer - 消费函数
      返回:
      children
    • not

      public Children not​(boolean condition, Consumer<Children> consumer)
      从接口复制的说明: Nested
      not嵌套

      例: not(i -> i.eq("name", "李白").ne("status", "活着"))

      指定者:
      not 在接口中 Nested<T,​R>
      参数:
      condition - 执行条件
      consumer - 消费函数
      返回:
      children
    • or

      public Children or​(boolean condition)
      从接口复制的说明: Join
      拼接 OR
      指定者:
      or 在接口中 Join<T>
      参数:
      condition - 执行条件
      返回:
      children
    • apply

      public Children apply​(boolean condition, String applySql, Object... value)
      从接口复制的说明: Join
      拼接 sql

      !! 会有 sql 注入风险 !!

      例1: apply("id = 1")

      例2: apply("date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")

      例3: apply("date_format(dateColumn,'%Y-%m-%d') = {0}", LocalDate.now())

      指定者:
      apply 在接口中 Join<T>
      参数:
      condition - 执行条件
      返回:
      children
    • last

      public Children last​(boolean condition, String lastSql)
      从接口复制的说明: Join
      无视优化规则直接拼接到 sql 的最后(有sql注入的风险,请谨慎使用)

      例: last("limit 1")

      注意只能调用一次,多次调用以最后一次为准

      指定者:
      last 在接口中 Join<T>
      参数:
      condition - 执行条件
      lastSql - sql语句
      返回:
      children
    • comment

      public Children comment​(boolean condition, String comment)
      从接口复制的说明: Join
      sql 注释(会拼接在 sql 的最后面)
      指定者:
      comment 在接口中 Join<T>
      参数:
      condition - 执行条件
      comment - sql注释
      返回:
      children
    • first

      public Children first​(boolean condition, String firstSql)
      从接口复制的说明: Join
      sql 起始句(会拼接在SQL语句的起始处)
      指定者:
      first 在接口中 Join<T>
      参数:
      condition - 执行条件
      firstSql - 起始语句
      返回:
      children
    • exists

      public Children exists​(boolean condition, String existsSql)
      从接口复制的说明: Join
      拼接 EXISTS ( sql语句 )

      !! sql 注入方法 !!

      例: exists("select id from table where age = 1")

      指定者:
      exists 在接口中 Join<T>
      参数:
      condition - 执行条件
      existsSql - sql语句
      返回:
      children
    • notExists

      public Children notExists​(boolean condition, String existsSql)
      从接口复制的说明: Join
      拼接 NOT EXISTS ( sql语句 )

      !! sql 注入方法 !!

      例: notExists("select id from table where age = 1")

      指定者:
      notExists 在接口中 Join<T>
      参数:
      condition - 执行条件
      existsSql - sql语句
      返回:
      children
    • isNull

      public Children isNull​(boolean condition, R column)
      从接口复制的说明: Func
      字段 IS NULL

      例: isNull("name")

      指定者:
      isNull 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      返回:
      children
    • isNotNull

      public Children isNotNull​(boolean condition, R column)
      从接口复制的说明: Func
      字段 IS NOT NULL

      例: isNotNull("name")

      指定者:
      isNotNull 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      返回:
      children
    • in

      public Children in​(boolean condition, R column, Collection<?> coll)
      从接口复制的说明: Func
      字段 IN (value.get(0), value.get(1), ...)

      例: in("id", Arrays.asList(1, 2, 3, 4, 5))

    • 如果集合为 empty 则不会进行 sql 拼接
    • 指定者:
      in 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      coll - 数据集合
      返回:
      children
    • notIn

      public Children notIn​(boolean condition, R column, Collection<?> coll)
      从接口复制的说明: Func
      字段 NOT IN (value.get(0), value.get(1), ...)

      例: notIn("id", Arrays.asList(1, 2, 3, 4, 5))

      指定者:
      notIn 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      coll - 数据集合
      返回:
      children
    • inSql

      public Children inSql​(boolean condition, R column, String inValue)
      从接口复制的说明: Func
      字段 IN ( sql语句 )

      !! sql 注入方式的 in 方法 !!

      例1: inSql("id", "1, 2, 3, 4, 5, 6")

      例2: inSql("id", "select id from table where id < 3")

      指定者:
      inSql 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      inValue - sql语句
      返回:
      children
    • notInSql

      public Children notInSql​(boolean condition, R column, String inValue)
      从接口复制的说明: Func
      字段 NOT IN ( sql语句 )

      !! sql 注入方式的 not in 方法 !!

      例1: notInSql("id", "1, 2, 3, 4, 5, 6")

      例2: notInSql("id", "select id from table where id < 3")

      指定者:
      notInSql 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      column - 字段
      inValue - sql语句 ---> 1,2,3,4,5,6 或者 select id from table where id < 3
      返回:
      children
    • groupBy

      public Children groupBy​(boolean condition, R... columns)
      从接口复制的说明: Func
      分组:GROUP BY 字段, ...

      例: groupBy("id", "name")

      指定者:
      groupBy 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      columns - 字段数组
      返回:
      children
    • orderBy

      public Children orderBy​(boolean condition, boolean isAsc, R... columns)
      从接口复制的说明: Func
      排序:ORDER BY 字段, ...

      例: orderBy(true, "id", "name")

      指定者:
      orderBy 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      isAsc - 是否是 ASC 排序
      columns - 字段数组
      返回:
      children
    • having

      public Children having​(boolean condition, String sqlHaving, Object... params)
      从接口复制的说明: Func
      HAVING ( sql语句 )

      例1: having("sum(age) > 10")

      例2: having("sum(age) > {0}", 10)

      指定者:
      having 在接口中 Func<T,​R>
      参数:
      condition - 执行条件
      sqlHaving - sql 语句
      params - 参数数组
      返回:
      children
    • func

      public Children func​(boolean condition, Consumer<Children> consumer)
      从接口复制的说明: Func
      消费函数
      指定者:
      func 在接口中 Func<T,​R>
      consumer - 消费函数
      返回:
      children
    • not

      protected Children not​(boolean condition)
      内部自用

      NOT 关键词

    • and

      protected Children and​(boolean condition)
      内部自用

      拼接 AND

    • likeValue

      protected Children likeValue​(boolean condition, SqlKeyword keyword, R column, Object val, SqlLike sqlLike)
      内部自用

      拼接 LIKE 以及 值

    • addCondition

      protected Children addCondition​(boolean condition, R column, SqlKeyword sqlKeyword, Object val)
      普通查询条件
      参数:
      condition - 是否执行
      column - 属性
      sqlKeyword - SQL 关键词
      val - 条件值
    • addNestedCondition

      protected Children addNestedCondition​(boolean condition, Consumer<Children> consumer)
      多重嵌套查询条件
      参数:
      condition - 查询条件值
    • instance

      protected abstract Children instance()
      子类返回一个自己的新对象
    • formatSql

      protected final String formatSql​(String sqlStr, Object... params)
      格式化SQL
      参数:
      sqlStr - SQL语句部分
      params - 参数集
      返回:
      sql
    • formatSqlIfNeed

      protected final String formatSqlIfNeed​(boolean need, String sqlStr, Object... params)

      根据需要格式化SQL

      Format SQL for methods: EntityQ.where/and/or...("name={0}", value); ALL the {i} will be replaced with #{MPGENVALi}

      ew.where("sample_name={0}", "haha").and("sample_age >{0} and sample_age<{1}", 18, 30) TO sample_name=#{MPGENVAL1} and sample_age>#{MPGENVAL2} and sample_age<#{MPGENVAL3}

      参数:
      need - 是否需要格式化
      sqlStr - SQL语句部分
      params - 参数集
      返回:
      sql
    • initNeed

      protected void initNeed()
      必要的初始化
    • clear

      public void clear()
      从类复制的说明: Wrapper
      条件清空
      指定者:
      clear 在类中 Wrapper<T>
    • doIt

      protected Children doIt​(boolean condition, ISqlSegment... sqlSegments)
      对sql片段进行组装
      参数:
      condition - 是否执行
      sqlSegments - sql片段数组
      返回:
      children
    • getSqlSegment

      public String getSqlSegment()
      从接口复制的说明: ISqlSegment
      SQL 片段
      指定者:
      getSqlSegment 在接口中 ISqlSegment
    • getSqlComment

      public String getSqlComment()
      覆盖:
      getSqlComment 在类中 Wrapper<T>
    • getSqlFirst

      public String getSqlFirst()
      覆盖:
      getSqlFirst 在类中 Wrapper<T>
    • getExpression

      public MergeSegments getExpression()
      从类复制的说明: Wrapper
      获取 MergeSegments
      指定者:
      getExpression 在类中 Wrapper<T>
    • getParamNameValuePairs

      public Map<String,​Object> getParamNameValuePairs()
    • columnToString

      protected String columnToString​(R column)
      获取 columnName
    • columnsToString

      protected String columnsToString​(R... columns)
      多字段转换为逗号 "," 分割字符串
      参数:
      columns - 多字段
    • clone

      public Children clone()
      覆盖:
      clone 在类中 Object