类 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
    • notLikeLeft

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

      public Children notLikeRight(boolean condition, R column, Object val)
      从接口复制的说明: Compare
      NOT LIKE '值%'
      指定者:
      notLikeRight 在接口中 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... values)
      从接口复制的说明: 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())

      例4: apply("type={0,javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler}", "待处理字符串")

      指定者:
      apply 在接口中 Join<T>
      参数:
      condition - 执行条件
      values - 数据数组
      返回:
      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 的最后面)

      自3.5.6开始,默认不处理转义字符,如有需要,调用StringEscape.escapeRawString(String)

      指定者:
      comment 在接口中 Join<T>
      参数:
      condition - 执行条件
      comment - sql注释
      返回:
      children
    • first

      public Children first(boolean condition, String firstSql)
      从接口复制的说明: Join
      sql 起始句(会拼接在SQL语句的起始处)

      自3.5.6开始,默认不处理转义字符,如有需要,调用StringEscape.escapeRawString(String)

      指定者:
      first 在接口中 Join<T>
      参数:
      condition - 执行条件
      firstSql - 起始语句
      返回:
      children
    • exists

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

      !! sql 注入方法 !!

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

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

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

      !! sql 注入方法 !!

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

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

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

      例: isNull(true, "name")

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

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

      例: isNotNull(true, "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(true, "id", Arrays.asList(1, 2, 3, 4, 5))

    • 注意!当集合为 空或null 时, sql会拼接为:WHERE (字段名 IN ()), 执行时报错
    • 若要在特定条件下不拼接, 可在 condition 条件中判断
    • 指定者:
      in 在接口中 Func<T,R>
      参数:
      condition - 执行条件
      column - 字段
      coll - 数据集合
      返回:
      children
    • in

      public Children in(boolean condition, R column, Object... values)
      从接口复制的说明: Func
      字段 IN (v0, v1, ...)

      例: in(true, "id", 1, 2, 3, 4, 5)

    • 注意!当数组为 空或null 时, sql会拼接为:WHERE (字段名 IN ()), 执行时报错
    • 若要在特定条件下不拼接, 可在 condition 条件中判断
    • 指定者:
      in 在接口中 Func<T,R>
      参数:
      condition - 执行条件
      column - 字段
      values - 数据数组
      返回:
      children
    • notIn

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

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

    • 注意!当集合为 空或null 时, sql会拼接为:WHERE (字段名 NOT IN ()), 执行时报错
    • 若要在特定条件下不拼接, 可在 condition 条件中判断
    • 指定者:
      notIn 在接口中 Func<T,R>
      参数:
      condition - 执行条件
      column - 字段
      coll - 数据集合
      返回:
      children
    • notIn

      public Children notIn(boolean condition, R column, Object... values)
      从接口复制的说明: Func
      字段 NOT IN (v0, v1, ...)

      例: notIn(true, "id", 1, 2, 3, 4, 5)

    • 注意!当数组为 空或null 时, sql会拼接为:WHERE (字段名 NOT IN ()), 执行时报错
    • 若要在特定条件下不拼接, 可在 condition 条件中判断
    • 指定者:
      notIn 在接口中 Func<T,R>
      参数:
      condition - 执行条件
      column - 字段
      values - 数据数组
      返回:
      children
    • eqSql

      public Children eqSql(boolean condition, R column, String eqValue)
      从接口复制的说明: Func
      字段 EQ ( sql语句 )

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

      例1: eqSql("id", "1")

      例2: eqSql("id", "select MAX(id) from table")

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

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

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

      例1: inSql(true, "id", "1")

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

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

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

      例1: gtSql(true, "id", "1")

      例1: gtSql(true, "id", "select id from table where name = 'JunJun'")

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

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

      例1: geSql(true, "id", "1")

      例1: geSql(true, "id", "select id from table where name = 'JunJun'")

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

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

      例1: ltSql(true, "id", "1")

      例1: ltSql(true , "id", "select id from table where name = 'JunJun'")

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

      public Children leSql(boolean condition, R column, String inValue)
      从接口复制的说明: Func
      字段 无效输入:'<'= ( sql语句 )

      例1: leSql(true, "id", "1")

      例1: leSql(true ,"id", "select id from table where name = 'JunJun'")

      指定者:
      leSql 在接口中 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(true, "id", "1, 2, 3, 4, 5, 6")

      例2: notInSql(true, "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 column, R... columns)
      从接口复制的说明: Func
      分组:GROUP BY 字段, ...

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

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

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

      例: groupBy(true, "id", Arrays.asList("name"))

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

      public Children doGroupBy(boolean condition, R column, List<R> columns)
    • doOrderBy

      public Children doOrderBy(boolean condition, boolean isAsc, R column, List<R> columns)
    • orderBy

      public Children orderBy(boolean condition, boolean isAsc, R column, R... columns)
      从接口复制的说明: Func
      排序:ORDER BY 字段, ...
      指定者:
      orderBy 在接口中 Func<T,R>
      参数:
      condition - 执行条件
      isAsc - 是否是 ASC 排序
      columns - 字段列表
      返回:
      children
    • orderBy

      public Children orderBy(boolean condition, boolean isAsc, R column, List<R> columns)
      从接口复制的说明: Func
      排序:ORDER BY 字段, ...
      指定者:
      orderBy 在接口中 Func<T,R>
      参数:
      condition - 执行条件
      isAsc - 是否是 ASC 排序
      columns - 字段列表
      返回:
      children
    • groupBy

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

      例: groupBy(true, "id")

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

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

      例: groupBy(true, Arrays.asList("id", "name"))

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

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

      例: orderBy(true, "id")

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

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

      例: orderBy(true, Arrays.asList("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(true, "sum(age) > 10")

      例2: having(true, "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>
      参数:
      condition - 执行条件
      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()
      子类返回一个自己的新对象
    • formatSqlMaybeWithParam

      protected final String formatSqlMaybeWithParam(String sqlStr, Object... params)
      格式化 sql

      支持 "{0}" 这种,或者 "sql {0} sql" 这种 也支持 "sql {0,javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler} sql" 这种

      参数:
      sqlStr - 可能是sql片段
      params - 参数
      返回:
      sql片段
    • formatParam

      protected final String formatParam(String mapping, Object param)
      处理入参
      参数:
      mapping - 例如: "javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler" 这种
      param - 参数
      返回:
      value
    • maybeDo

      protected final Children maybeDo(boolean condition, AbstractWrapper.DoSomething something)
      函数化的做事
      参数:
      condition - 做不做
      something - 做什么
      返回:
      Children
    • inExpression

      protected ISqlSegment inExpression(Collection<?> value)
      获取in表达式 包含括号
      参数:
      value - 集合
    • inExpression

      protected ISqlSegment inExpression(Object[] values)
      获取in表达式 包含括号
      参数:
      values - 数组
    • initNeed

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

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

      protected void appendSqlSegments(ISqlSegment... sqlSegments)
      添加 where 片段
      参数:
      sqlSegments - ISqlSegment 数组
    • isUseAnnotationOrderBy

      public boolean isUseAnnotationOrderBy()
      是否使用默认注解 OrderBy 排序
      返回:
      true 使用 false 不使用
    • 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>
    • getParamAlias

      public String getParamAlias()
    • setParamAlias

      public Children setParamAlias(String paramAlias)
      参数别名设置,初始化时优先设置该值、重复设置异常
      参数:
      paramAlias - 参数别名
      返回:
      Children
    • columnToSqlSegment

      protected final ColumnSegment columnToSqlSegment(R column)
      获取 columnName
    • columnToString

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

      protected String columnsToString(R... columns)
      获取 columnNames
    • columnsToString

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

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

      public Map<String,Object> getParamNameValuePairs()