浏览代码

玩的就是心跳

hubin 7 年之前
父节点
当前提交
cc19bc3d2d
共有 28 个文件被更改,包括 2165 次插入1732 次删除
  1. 2 0
      build.gradle
  2. 0 3
      mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/Condition.java
  3. 0 2
      mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/EntityWrapper.java
  4. 1584 0
      mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/Wrapper.java
  5. 0 63
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Condition.java
  6. 4 87
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/EntityWrapper.java
  7. 1 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/MybatisAbstractSQL.java
  8. 1 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/SqlPlus.java
  9. 2 14
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/UpdateWrapper.java
  10. 5 1546
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Wrapper.java
  11. 9 9
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/sql/SqlHelper.java
  12. 1 1
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/Main.java
  13. 11 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/ISqlSegment.java
  14. 12 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/Keywords.java
  15. 83 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/Query.java
  16. 103 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/QueryTest.java
  17. 19 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Column.java
  18. 36 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/From.java
  19. 41 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Join.java
  20. 20 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Select.java
  21. 19 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Where.java
  22. 58 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/predicate/Condition.java
  23. 18 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/predicate/On.java
  24. 100 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/predicate/Table.java
  25. 6 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/struct/SimpleQueue.java
  26. 30 0
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/struct/Statement.java
  27. 0 6
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/test/GlobalConfigurationTest.java
  28. 0 1
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/test/mysql/LogicDeleteTest.java

+ 2 - 0
build.gradle

@@ -27,6 +27,7 @@ ext {
         //test
         "spring-test"           : "org.springframework:spring-test:${springVersion}",
         "junit"                 : "junit:junit:4.12",
+        "mockito-all"                 : "org.mockito:mockito-all:1.10.19",
         "lombok"                : "org.projectlombok:lombok:1.16.20",
         "fastjson"              : "com.alibaba:fastjson:1.2.37",
         "tomcatjdbc"            : "org.apache.tomcat:tomcat-jdbc:9.0.2",
@@ -91,6 +92,7 @@ subprojects {
 
     dependencies {
         compileOnly rootProject.ext.dependencies["lombok"]
+        testCompile rootProject.ext.dependencies["mockito-all"]
         testCompile rootProject.ext.dependencies["lombok"]
         testCompile rootProject.ext.dependencies["junit"]
     }

+ 0 - 3
mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/Condition.java

@@ -1,8 +1,5 @@
 package com.baomidou.mybatisplus.mapper;
 
-import com.baomidou.mybatisplus.core.conditions.EntityWrapper;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-
 /**
  * 请尽快修改该类的引用 mp 3.1 将删除该类
  */

+ 0 - 2
mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/EntityWrapper.java

@@ -1,7 +1,5 @@
 package com.baomidou.mybatisplus.mapper;
 
-
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.metadata.Column;
 import com.baomidou.mybatisplus.core.metadata.Columns;
 import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;

+ 1584 - 0
mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/Wrapper.java

@@ -0,0 +1,1584 @@
+/*
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.mapper;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.baomidou.mybatisplus.core.conditions.SqlPlus;
+import com.baomidou.mybatisplus.core.enums.SqlLike;
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.MapUtils;
+import com.baomidou.mybatisplus.core.toolkit.SerializationUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.TableInfoHelper;
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
+import com.baomidou.mybatisplus.core.toolkit.support.Property;
+
+
+/**
+ * <p>
+ * 条件构造抽象类,定义T-SQL语法
+ * </p>
+ *
+ * @author hubin , yanghu , Dyang , Caratacus, hcl
+ * @Date 2016-11-7
+ */
+@Deprecated
+public abstract class Wrapper<T> extends com.baomidou.mybatisplus.core.conditions.Wrapper<T> {
+
+    /**
+     * 占位符
+     */
+    private static final String PLACE_HOLDER = "{%s}";
+
+    private static final String MYBATIS_PLUS_TOKEN = "#{%s.paramNameValuePairs.%s}";
+
+    private static final String MP_GENERAL_PARAMNAME = "MPGENVAL";
+
+    private static final String DEFAULT_PARAM_ALIAS = "ew";
+    /**
+     * 实现了TSQL语法的SQL实体
+     */
+    protected final SqlPlus sql = new SqlPlus();
+    private final Map<String, Object> paramNameValuePairs = new HashMap<>();
+    private final AtomicInteger paramNameSeq = new AtomicInteger(0);
+    protected String paramAlias = null;
+    /**
+     * 自定义是否输出sql为 WHERE OR AND OR OR
+     */
+    protected Boolean isWhere;
+    /**
+     * 拼接WHERE后应该是AND还是ORnull
+     */
+    protected String AND_OR = "AND";
+
+    /**
+     * <p>
+     * 兼容EntityWrapper
+     * </p>
+     *
+     * @return
+     */
+    @Override
+    public T getEntity() {
+        return null;
+    }
+
+    /**
+     * 查看where构造是否为空
+     *
+     * @return
+     */
+    public boolean isEmptyOfWhere() {
+        return sql.isEmptyOfWhere();
+    }
+
+    /**
+     * 查看where构造是否不为空
+     *
+     * @return
+     */
+    public boolean isNotEmptyOfWhere() {
+        return !isEmptyOfWhere();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("Wrapper<T>:");
+        String sqlSegment = getSqlSegment();
+        sb.append(replacePlaceholder(sqlSegment));
+        Object entity = getEntity();
+        if (entity != null) {
+            sb.append("\n");
+            sb.append("entity=").append(entity.toString());
+        }
+        return sb.toString();
+    }
+
+    /**
+     * <p>
+     * 替换占位符
+     * </p>
+     *
+     * @param sqlSegment
+     * @return
+     */
+    private String replacePlaceholder(String sqlSegment) {
+        if (StringUtils.isEmpty(sqlSegment)) {
+            return StringUtils.EMPTY;
+        }
+        return sqlSegment.replaceAll("#\\{" + getParamAlias() + ".paramNameValuePairs.MPGENVAL[0-9]+}", "\\?");
+    }
+
+    /**
+     * <p>
+     * 原生占位符sql
+     * </p>
+     *
+     * @return
+     */
+    public String originalSql() {
+        return replacePlaceholder(getSqlSegment());
+    }
+
+    /**
+     * <p>
+     * SQL中WHERE关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").where(id!=null, "id={0}", id);
+     * <p>
+     * 输出:<br>
+     * 如果id=123:  WHERE (NAME='zhangsan' AND id=123)<br>
+     * 如果id=null: WHERE (NAME='zhangsan')
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param sqlWhere  where语句
+     * @param params    参数集
+     * @return this
+     */
+    public Wrapper<T> where(boolean condition, String sqlWhere, Object... params) {
+        if (condition) {
+            sql.WHERE(formatSql(sqlWhere, params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * SQL中WHERE关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").where("id={0}","123");
+     * <p>
+     * 输出: WHERE (NAME='zhangsan' AND id=123)
+     * </p>
+     *
+     * @param sqlWhere where语句
+     * @param params   参数集
+     * @return this
+     */
+    public Wrapper<T> where(String sqlWhere, Object... params) {
+        return where(true, sqlWhere, params);
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field=value"表达式
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> eq(boolean condition, String column, Object params) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s = {0}", column), params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field=value"表达式
+     * </p>
+     *
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> eq(String column, Object params) {
+        return eq(true, column, params);
+    }
+
+    public Wrapper<T> eq(boolean condition, Property<T, ?> func, Object params) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s = {0}", toCol(func)), params));
+        }
+        return this;
+    }
+
+    /**
+     * 为了支持字段重构做出的修改
+     * <p>
+     * 你可以在指定 Wrapper<T> 泛型的前提下这么使用:
+     * <p>
+     * Wrapper<User> wrapper = new EntityWrapper<User>();
+     * wrapper.eq(User::getUserName, "baomidou")
+     * <p>
+     * 改方法会根据规则(比如配置的字段映射、或者下划线规则)将 User::getUserName 转换为对应的数据库字段信息
+     *
+     * @param func   需要转换的 function
+     * @param params 参数信息
+     * @return 返回自身
+     */
+    public Wrapper<T> eq(Property<T, ?> func, Object params) {
+        return eq(true, func, params);
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field <> value"表达式
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> ne(boolean condition, String column, Object params) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s <> {0}", column), params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field <> value"表达式
+     * </p>
+     *
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> ne(String column, Object params) {
+        return ne(true, column, params);
+
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field=value"表达式
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param params
+     * @return
+     */
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    public Wrapper<T> allEq(boolean condition, Map<String, Object> params) {
+        if (condition && MapUtils.isNotEmpty(params)) {
+            Iterator iterator = params.entrySet().iterator();
+            while (iterator.hasNext()) {
+                Map.Entry<String, Object> entry = (Map.Entry<String, Object>) iterator.next();
+                Object value = entry.getValue();
+                if (StringUtils.checkValNotNull(value)) {
+                    sql.WHERE(formatSql(String.format("%s = {0}", entry.getKey()), entry.getValue()));
+                }
+
+            }
+
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field=value"表达式
+     * </p>
+     *
+     * @param params
+     * @return
+     */
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    public Wrapper<T> allEq(Map<String, Object> params) {
+        return allEq(true, params);
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field>value"表达式
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> gt(boolean condition, String column, Object params) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s > {0}", column), params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field>value"表达式
+     * </p>
+     *
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> gt(String column, Object params) {
+        return gt(true, column, params);
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field>=value"表达式
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> ge(boolean condition, String column, Object params) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s >= {0}", column), params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field>=value"表达式
+     * </p>
+     *
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> ge(String column, Object params) {
+        return ge(true, column, params);
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field<value"表达式
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> lt(boolean condition, String column, Object params) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s < {0}", column), params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field<value"表达式
+     * </p>
+     *
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> lt(String column, Object params) {
+        return lt(true, column, params);
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field<=value"表达式
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> le(boolean condition, String column, Object params) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s <= {0}", column), params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 等同于SQL的"field<=value"表达式
+     * </p>
+     *
+     * @param column
+     * @param params
+     * @return
+     */
+    public Wrapper<T> le(String column, Object params) {
+        return le(true, column, params);
+    }
+
+    /**
+     * <p>
+     * AND 连接后续条件
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param sqlAnd    and条件语句
+     * @param params    参数集
+     * @return this
+     */
+    public Wrapper<T> and(boolean condition, String sqlAnd, Object... params) {
+        if (condition) {
+            sql.AND().WHERE(formatSql(sqlAnd, params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * AND 连接后续条件
+     * </p>
+     *
+     * @param sqlAnd and条件语句
+     * @param params 参数集
+     * @return this
+     */
+    public Wrapper<T> and(String sqlAnd, Object... params) {
+        return and(true, sqlAnd, params);
+    }
+
+    /**
+     * <p>
+     * 使用AND连接并换行
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").and("id=11").andNew("statu=1"); 输出: WHERE
+     * (name='zhangsan' AND id=11) AND (statu=1)
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param sqlAnd    AND 条件语句
+     * @param params    参数值
+     * @return this
+     */
+    public Wrapper<T> andNew(boolean condition, String sqlAnd, Object... params) {
+        if (condition) {
+            sql.AND_NEW().WHERE(formatSql(sqlAnd, params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用AND连接并换行
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").and("id=11").andNew("statu=1"); 输出: WHERE
+     * (name='zhangsan' AND id=11) AND (statu=1)
+     * </p>
+     *
+     * @return this
+     */
+    public Wrapper<T> andNew() {
+        sql.AND_NEW();
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用AND连接并换行
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").and("id=11").andNew("statu=1"); 输出: WHERE
+     * (name='zhangsan' AND id=11) AND (statu=1)
+     * </p>
+     *
+     * @param sqlAnd AND 条件语句
+     * @param params 参数值
+     * @return this
+     */
+    public Wrapper<T> andNew(String sqlAnd, Object... params) {
+        return andNew(true, sqlAnd, params);
+    }
+
+    /**
+     * <p>
+     * 使用AND连接并换行
+     * </p>
+     *
+     * @return this
+     */
+    public Wrapper<T> and() {
+        sql.AND();
+        return this;
+    }
+
+    /**
+     * <p>
+     * 左嵌套方法
+     * </p>
+     *
+     * @return this
+     */
+    public Wrapper<T> leftNest() {
+        leftNest(1);
+        return this;
+    }
+
+    /**
+     * <p>
+     * 右嵌套方法
+     * </p>
+     *
+     * @return this
+     */
+    public Wrapper<T> rightNest() {
+        rightNest(1);
+        return this;
+    }
+
+    /**
+     * <p>
+     * 左嵌套方法,一般认为填补mp一个条件中多重嵌套解决方案
+     * </p>
+     *
+     * @param num 嵌套数量
+     * @return this
+     */
+    public Wrapper<T> leftNest(int num) {
+        nest("(", num);
+        return this;
+    }
+
+    /**
+     * <p>
+     * 右嵌套方法,一般认为填补mp一个条件中多重嵌套解决方案
+     * </p>
+     *
+     * @param num 嵌套数量
+     * @return this
+     */
+    public Wrapper<T> rightNest(int num) {
+        nest(")", num);
+        return this;
+    }
+
+    /**
+     * <p>
+     * 嵌套方法,一般认为填补mp一个条件中多重嵌套解决方案
+     * </p>
+     *
+     * @param nest 嵌套字符串 "(" or ")"
+     * @param num  嵌套数量
+     * @return this
+     */
+    private Wrapper<T> nest(String nest, int num) {
+        if (num >= 1) {
+            StringBuilder builder = new StringBuilder(num);
+            for (int i = 0; i < num; i++) {
+                builder.append(nest);
+            }
+            sql.SUPP(builder.toString());
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用OR连接并换行
+     * </p>
+     *
+     * @return this
+     */
+    public Wrapper<T> or() {
+        sql.OR();
+        return this;
+    }
+
+    /**
+     * <p>
+     * 添加OR条件
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param sqlOr     or 条件语句
+     * @param params    参数集
+     * @return this
+     */
+    public Wrapper<T> or(boolean condition, String sqlOr, Object... params) {
+        if (condition) {
+            if (StringUtils.isEmpty(sql.toString())) {
+                AND_OR = "OR";
+            }
+            sql.OR().WHERE(formatSql(sqlOr, params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 添加OR条件
+     * </p>
+     *
+     * @param sqlOr  or 条件语句
+     * @param params 参数集
+     * @return this
+     */
+    public Wrapper<T> or(String sqlOr, Object... params) {
+        return or(true, sqlOr, params);
+    }
+
+    /**
+     * <p>
+     * 使用OR换行,并添加一个带()的新的条件
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").and("id=11").orNew("statu=1"); 输出: WHERE
+     * (name='zhangsan' AND id=11) OR (statu=1)
+     * </p>
+     *
+     * @return this
+     */
+    public Wrapper<T> orNew() {
+        sql.OR_NEW();
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用OR换行,并添加一个带()的新的条件
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").and("id=11").orNew("statu=1"); 输出: WHERE
+     * (name='zhangsan' AND id=11) OR (statu=1)
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param sqlOr     AND 条件语句
+     * @param params    参数值
+     * @return this
+     */
+    public Wrapper<T> orNew(boolean condition, String sqlOr, Object... params) {
+        if (condition) {
+            if (StringUtils.isEmpty(sql.toString())) {
+                AND_OR = "OR";
+            }
+            sql.OR_NEW().WHERE(formatSql(sqlOr, params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用OR换行,并添加一个带()的新的条件
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").and("id=11").orNew("statu=1"); 输出: WHERE
+     * (name='zhangsan' AND id=11) OR (statu=1)
+     * </p>
+     *
+     * @param sqlOr  AND 条件语句
+     * @param params 参数值
+     * @return this
+     */
+    public Wrapper<T> orNew(String sqlOr, Object... params) {
+        return orNew(true, sqlOr, params);
+    }
+
+    /**
+     * <p>
+     * SQL中groupBy关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").groupBy("id,name")
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param columns   SQL 中的 Group by 语句,无需输入 Group By 关键字
+     * @return this
+     */
+    public Wrapper<T> groupBy(boolean condition, String columns) {
+        if (condition) {
+            sql.GROUP_BY(columns);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * SQL中groupBy关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.where("name='zhangsan'").groupBy("id,name")
+     * </p>
+     *
+     * @param columns SQL 中的 Group by 语句,无需输入 Group By 关键字
+     * @return this
+     */
+    public Wrapper<T> groupBy(String columns) {
+        return groupBy(true, columns);
+    }
+
+    /**
+     * <p>
+     * SQL中having关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null")
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param sqlHaving having关键字后面跟随的语句
+     * @param params    参数集
+     * @return EntityWrapper<T>
+     */
+    public Wrapper<T> having(boolean condition, String sqlHaving, Object... params) {
+        if (condition) {
+            sql.HAVING(formatSql(sqlHaving, params));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * SQL中having关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null")
+     * </p>
+     *
+     * @param sqlHaving having关键字后面跟随的语句
+     * @param params    参数集
+     * @return EntityWrapper<T>
+     */
+    public Wrapper<T> having(String sqlHaving, Object... params) {
+        return having(true, sqlHaving, params);
+    }
+
+    /**
+     * <p>
+     * SQL中orderby关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null"
+     * ).orderBy("id,name")
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param columns   SQL 中的 order by 语句,无需输入 Order By 关键字
+     * @return this
+     */
+    public Wrapper<T> orderBy(boolean condition, String columns) {
+        if (condition) {
+            sql.ORDER_BY(columns);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * SQL中orderby关键字跟的条件语句
+     * </p>
+     * <p>
+     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null"
+     * ).orderBy("id,name")
+     * </p>
+     *
+     * @param columns SQL 中的 order by 语句,无需输入 Order By 关键字
+     * @return this
+     */
+    public Wrapper<T> orderBy(String columns) {
+        return orderBy(true, columns);
+    }
+
+    /**
+     * <p>
+     * SQL中orderby关键字跟的条件语句,可根据变更动态排序
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param columns   SQL 中的 order by 语句,无需输入 Order By 关键字
+     * @param isAsc     是否为升序
+     * @return this
+     */
+    public Wrapper<T> orderBy(boolean condition, String columns, boolean isAsc) {
+        if (condition && StringUtils.isNotEmpty(columns)) {
+            sql.ORDER_BY(columns + (isAsc ? " ASC" : " DESC"));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * SQL中orderby关键字跟的条件语句,可根据变更动态排序
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param columns   SQL 中的 order by 语句,无需输入 Order By 关键字
+     * @param isAsc     是否为升序
+     * @return this
+     */
+    public Wrapper<T> orderBy(boolean condition, Collection<String> columns, boolean isAsc) {
+        if (condition && CollectionUtils.isNotEmpty(columns)) {
+            for (String column : columns) {
+                orderBy(condition, column, isAsc);
+            }
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * SQL中orderby关键字跟的条件语句,可根据变更动态排序
+     * </p>
+     *
+     * @param columns SQL 中的 order by 语句,无需输入 Order By 关键字
+     * @param isAsc   是否为升序
+     * @return this
+     */
+    public Wrapper<T> orderBy(String columns, boolean isAsc) {
+        return orderBy(true, columns, isAsc);
+    }
+
+    /**
+     * <p>
+     * 批量根据ASC排序
+     * </p>
+     *
+     * @param columns 需要排序的集合
+     * @return this
+     */
+    public Wrapper<T> orderAsc(Collection<String> columns) {
+        return orderBy(true, columns, true);
+    }
+
+    /**
+     * <p>
+     * 批量根据DESC排序
+     * </p>
+     *
+     * @param columns 需要排序的集合
+     * @return this
+     */
+    public Wrapper<T> orderDesc(Collection<String> columns) {
+        return orderBy(true, columns, false);
+    }
+
+    /**
+     * <p>
+     * LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值
+     * @return this
+     */
+    public Wrapper<T> like(boolean condition, String column, String value) {
+        if (condition) {
+            handlerLike(column, value, SqlLike.DEFAULT, false);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值
+     * @return this
+     */
+    public Wrapper<T> like(String column, String value) {
+        return like(true, column, value);
+    }
+
+    /**
+     * <p>
+     * NOT LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值
+     * @return this
+     */
+    public Wrapper<T> notLike(boolean condition, String column, String value) {
+        if (condition) {
+            handlerLike(column, value, SqlLike.DEFAULT, true);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * NOT LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值
+     * @return this
+     */
+    public Wrapper<T> notLike(String column, String value) {
+        return notLike(true, column, value);
+    }
+
+    /**
+     * <p>
+     * 处理LIKE操作
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  like匹配值
+     * @param isNot  是否为NOT LIKE操作
+     */
+    private void handlerLike(String column, String value, SqlLike type, boolean isNot) {
+        if (StringUtils.isNotEmpty(column) && StringUtils.isNotEmpty(value)) {
+            StringBuilder inSql = new StringBuilder();
+            inSql.append(column);
+            if (isNot) {
+                inSql.append(" NOT");
+            }
+            inSql.append(" LIKE {0}");
+            sql.WHERE(formatSql(inSql.toString(), SqlUtils.concatLike(value, type)));
+        }
+    }
+
+    /**
+     * <p>
+     * LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值
+     * @param type
+     * @return this
+     */
+    public Wrapper<T> like(boolean condition, String column, String value, SqlLike type) {
+        if (condition) {
+            handlerLike(column, value, type, false);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值
+     * @param type
+     * @return this
+     */
+    public Wrapper<T> like(String column, String value, SqlLike type) {
+        return like(true, column, value, type);
+    }
+
+    /**
+     * <p>
+     * NOT LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值
+     * @param type
+     * @return this
+     */
+    public Wrapper<T> notLike(boolean condition, String column, String value, SqlLike type) {
+        if (condition) {
+            handlerLike(column, value, type, true);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * NOT LIKE条件语句,value中无需前后%
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值
+     * @param type
+     * @return this
+     */
+    public Wrapper<T> notLike(String column, String value, SqlLike type) {
+        return notLike(true, column, value, type);
+    }
+
+    /**
+     * <p>
+     * is not null 条件
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param columns   字段名称。多个字段以逗号分隔。
+     * @return this
+     */
+    public Wrapper<T> isNotNull(boolean condition, String columns) {
+        if (condition) {
+            sql.IS_NOT_NULL(columns);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * is not null 条件
+     * </p>
+     *
+     * @param columns 字段名称。多个字段以逗号分隔。
+     * @return this
+     */
+    public Wrapper<T> isNotNull(String columns) {
+        return isNotNull(true, columns);
+    }
+
+    /**
+     * <p>
+     * is null 条件
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param columns   字段名称。多个字段以逗号分隔。
+     * @return this
+     */
+    public Wrapper<T> isNull(boolean condition, String columns) {
+        if (condition) {
+            sql.IS_NULL(columns);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * is null 条件
+     * </p>
+     *
+     * @param columns 字段名称。多个字段以逗号分隔。
+     * @return this
+     */
+    public Wrapper<T> isNull(String columns) {
+        return isNull(true, columns);
+    }
+
+    /**
+     * <p>
+     * EXISTS 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param value     匹配值
+     * @return this
+     */
+    public Wrapper<T> exists(boolean condition, String value) {
+        if (condition) {
+            sql.EXISTS(value);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * EXISTS 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param value 匹配值
+     * @return this
+     */
+    public Wrapper<T> exists(String value) {
+        return exists(true, value);
+    }
+
+    /**
+     * <p>
+     * NOT EXISTS条件语句
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param value     匹配值
+     * @return this
+     */
+    public Wrapper<T> notExists(boolean condition, String value) {
+        if (condition) {
+            sql.NOT_EXISTS(value);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * NOT EXISTS条件语句
+     * </p>
+     *
+     * @param value 匹配值
+     * @return this
+     */
+    public Wrapper<T> notExists(String value) {
+        return notExists(true, value);
+    }
+
+    /**
+     * <p>
+     * IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     逗号拼接的字符串
+     * @return this
+     */
+    public Wrapper<T> in(boolean condition, String column, String value) {
+        if (condition && StringUtils.isNotEmpty(value)) {
+            in(column, StringUtils.splitWorker(value, ",", -1, false));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  逗号拼接的字符串
+     * @return this
+     */
+    public Wrapper<T> in(String column, String value) {
+        return in(true, column, value);
+    }
+
+    /**
+     * <p>
+     * NOT IN条件语句
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     逗号拼接的字符串
+     * @return this
+     */
+    public Wrapper<T> notIn(boolean condition, String column, String value) {
+        if (condition && StringUtils.isNotEmpty(value)) {
+            notIn(column, StringUtils.splitWorker(value, ",", -1, false));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * NOT IN条件语句
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  逗号拼接的字符串
+     * @return this
+     */
+    public Wrapper<T> notIn(String column, String value) {
+        return notIn(true, column, value);
+    }
+
+    /**
+     * <p>
+     * IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值 集合
+     * @return this
+     */
+    public Wrapper<T> in(boolean condition, String column, Collection<?> value) {
+        if (condition && CollectionUtils.isNotEmpty(value)) {
+            sql.WHERE(formatSql(inExpression(column, value, false), value.toArray()));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值 集合
+     * @return this
+     */
+    public Wrapper<T> in(String column, Collection<?> value) {
+        return in(true, column, value);
+    }
+
+    /**
+     * <p>
+     * NOT IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值 集合
+     * @return this
+     */
+    public Wrapper<T> notIn(boolean condition, String column, Collection<?> value) {
+        if (condition && CollectionUtils.isNotEmpty(value)) {
+            sql.WHERE(formatSql(inExpression(column, value, true), value.toArray()));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * NOT IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值 集合
+     * @return this
+     */
+    public Wrapper<T> notIn(String column, Collection<?> value) {
+        return notIn(true, column, value);
+    }
+
+    /**
+     * <p>
+     * IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值 object数组
+     * @return this
+     */
+    public Wrapper<T> in(boolean condition, String column, Object[] value) {
+        if (condition && ArrayUtils.isNotEmpty(value)) {
+            sql.WHERE(formatSql(inExpression(column, Arrays.asList(value), false), value));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值 object数组
+     * @return this
+     */
+    public Wrapper<T> in(String column, Object[] value) {
+        return in(true, column, value);
+    }
+
+    /**
+     * <p>
+     * NOT IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param value     匹配值 object数组
+     * @return this
+     */
+    public Wrapper<T> notIn(boolean condition, String column, Object... value) {
+        if (condition && ArrayUtils.isNotEmpty(value)) {
+            sql.WHERE(formatSql(inExpression(column, Arrays.asList(value), true), value));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * NOT IN 条件语句,目前适配mysql及oracle
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  匹配值 object数组
+     * @return this
+     */
+    public Wrapper<T> notIn(String column, Object... value) {
+        return notIn(true, column, value);
+    }
+
+    /**
+     * <p>
+     * 获取in表达式
+     * </p>
+     *
+     * @param column 字段名称
+     * @param value  集合
+     * @param isNot  是否为NOT IN操作
+     */
+    private String inExpression(String column, Collection<?> value, boolean isNot) {
+        if (StringUtils.isNotEmpty(column) && CollectionUtils.isNotEmpty(value)) {
+            StringBuilder inSql = new StringBuilder();
+            inSql.append(column);
+            if (isNot) {
+                inSql.append(" NOT");
+            }
+            inSql.append(" IN ");
+            inSql.append("(");
+            int size = value.size();
+            for (int i = 0; i < size; i++) {
+                inSql.append(String.format(PLACE_HOLDER, i));
+                if (i + 1 < size) {
+                    inSql.append(",");
+                }
+            }
+            inSql.append(")");
+            return inSql.toString();
+        }
+        return null;
+    }
+
+    /**
+     * <p>
+     * betwwee 条件语句
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param val1
+     * @param val2
+     * @return this
+     */
+    public Wrapper<T> between(boolean condition, String column, Object val1, Object val2) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s BETWEEN {0} AND {1}", column), val1, val2));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * betwwee 条件语句
+     * </p>
+     *
+     * @param column 字段名称
+     * @param val1
+     * @param val2
+     * @return this
+     */
+    public Wrapper<T> between(String column, Object val1, Object val2) {
+        return between(true, column, val1, val2);
+    }
+
+    /**
+     * <p>
+     * NOT betwwee 条件语句
+     * </p>
+     *
+     * @param condition 拼接的前置条件
+     * @param column    字段名称
+     * @param val1
+     * @param val2
+     * @return this
+     */
+    public Wrapper<T> notBetween(boolean condition, String column, Object val1, Object val2) {
+        if (condition) {
+            sql.WHERE(formatSql(String.format("%s NOT BETWEEN {0} AND {1}", column), val1, val2));
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * NOT betwwee 条件语句
+     * </p>
+     *
+     * @param column 字段名称
+     * @param val1
+     * @param val2
+     * @return this
+     */
+    public Wrapper<T> notBetween(String column, Object val1, Object val2) {
+        return notBetween(true, column, val1, val2);
+
+    }
+
+    /**
+     * <p>
+     * 为了兼容之前的版本,可使用where()或and()替代
+     * </p>
+     *
+     * @param sqlWhere where sql部分
+     * @param params   参数集
+     * @return this
+     */
+    public Wrapper<T> addFilter(String sqlWhere, Object... params) {
+        return and(sqlWhere, params);
+    }
+
+    /**
+     * <p>
+     * 根据判断条件来添加条件语句部分 使用 andIf() 替代
+     * </p>
+     * <p>
+     * eg: ew.filterIfNeed(false,"name='zhangsan'").where("name='zhangsan'")
+     * .filterIfNeed(true,"id={0}",22)
+     * <p>
+     * 输出: WHERE (name='zhangsan' AND id=22)
+     * </p>
+     *
+     * @param need     是否需要添加该条件
+     * @param sqlWhere 条件语句
+     * @param params   参数集
+     * @return this
+     */
+    public Wrapper<T> addFilterIfNeed(boolean need, String sqlWhere, Object... params) {
+        return need ? where(sqlWhere, params) : this;
+    }
+
+    /**
+     * <p>
+     * 格式化SQL
+     * </p>
+     *
+     * @param sqlStr SQL语句部分
+     * @param params 参数集
+     * @return this
+     */
+    protected String formatSql(String sqlStr, Object... params) {
+        return formatSqlIfNeed(true, sqlStr, params);
+    }
+
+    /**
+     * <p>
+     * 根据需要格式化SQL<BR>
+     * <BR>
+     * Format SQL for methods: EntityWrapper<T>.where/and/or...("name={0}", value);
+     * ALL the {<b>i</b>} will be replaced with #{MPGENVAL<b>i</b>}<BR>
+     * <BR>
+     * ew.where("sample_name=<b>{0}</b>", "haha").and("sample_age &gt;<b>{0}</b>
+     * and sample_age&lt;<b>{1}</b>", 18, 30) <b>TO</b>
+     * sample_name=<b>#{MPGENVAL1}</b> and sample_age&gt;#<b>{MPGENVAL2}</b> and
+     * sample_age&lt;<b>#{MPGENVAL3}</b><BR>
+     * </p>
+     *
+     * @param need   是否需要格式化
+     * @param sqlStr SQL语句部分
+     * @param params 参数集
+     * @return this
+     */
+    protected String formatSqlIfNeed(boolean need, String sqlStr, Object... params) {
+        if (!need || StringUtils.isEmpty(sqlStr)) {
+            return null;
+        }
+        // #200
+        if (ArrayUtils.isNotEmpty(params)) {
+            for (int i = 0; i < params.length; ++i) {
+                String genParamName = MP_GENERAL_PARAMNAME + paramNameSeq.incrementAndGet();
+                sqlStr = sqlStr.replace(String.format(PLACE_HOLDER, i),
+                    String.format(MYBATIS_PLUS_TOKEN, getParamAlias(), genParamName));
+                paramNameValuePairs.put(genParamName, params[i]);
+            }
+        }
+        return sqlStr;
+    }
+
+    /**
+     * <p>
+     * 自定义是否输出sql开头为 `WHERE` OR `AND` OR `OR`
+     * </p>
+     *
+     * @param bool
+     * @return this
+     */
+    public Wrapper<T> isWhere(Boolean bool) {
+        this.isWhere = bool;
+        return this;
+    }
+
+    /**
+     * <p>
+     * 手动把sql拼接到最后(有sql注入的风险,请谨慎使用)
+     * </p>
+     *
+     * @param limit
+     * @return this
+     */
+    public Wrapper<T> last(String limit) {
+        sql.LAST(limit);
+        return this;
+    }
+
+    /**
+     * Fix issue 200.
+     *
+     * @return
+     * @since 2.0.3
+     */
+    public Map<String, Object> getParamNameValuePairs() {
+        return paramNameValuePairs;
+    }
+
+    public String getParamAlias() {
+        return StringUtils.isEmpty(paramAlias) ? DEFAULT_PARAM_ALIAS : paramAlias;
+    }
+
+    /**
+     * <p>
+     * 参数别名设置,初始化时优先设置该值、重复设置异常
+     * </p>
+     *
+     * @param paramAlias 参数别名
+     * @return
+     */
+    public Wrapper<T> setParamAlias(String paramAlias) {
+        if (StringUtils.isNotEmpty(getSqlSegment())) {
+            throw new MybatisPlusException("Error: Please call this method when initializing!");
+        }
+        if (StringUtils.isNotEmpty(this.paramAlias)) {
+            throw new MybatisPlusException("Error: Please do not call the method repeatedly!");
+        }
+        this.paramAlias = paramAlias;
+        return this;
+    }
+
+    /**
+     * 是否为空
+     */
+    public boolean isEmpty() {
+        return sql.isEmptyOfWhere();
+    }
+
+    public static <T> Wrapper<T> getInstance() {
+        return new Wrapper<T>() {
+            @Override
+            public String getSqlSegment() {
+                return null;
+            }
+        };
+    }
+
+    /**
+     * <p>
+     * 克隆本身 fixed github issues/241
+     * </p>
+     */
+    @Override
+    public Wrapper<T> clone() {
+        return SerializationUtils.clone(this);
+    }
+
+    /**
+     * @param func function
+     * @return 返回从 function 中解析出的 column
+     */
+    protected String toCol(Property<T, ?> func) {
+        return TableInfoHelper.toColumn(func);
+    }
+}
+

+ 0 - 63
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Condition.java

@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2011-2020, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR EntityWrapperS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.core.conditions;
-
-/**
- * <p>
- * 条件查询构造器
- * </p>
- *
- * @author hubin Caratacus
- * @date 2016-11-7
- */
-public abstract class Condition {
-
-    /**
-     * 构建一个Empty条件构造 避免传递参数使用null
-     */
-    public static final Wrapper EMPTY = Wrapper.getInstance();
-
-    /**
-     * 构造一个空的Wrapper<T></>
-     *
-     * @param <T>
-     * @return
-     */
-    public static <T> Wrapper<T> empty() {
-        return (Wrapper<T>) EMPTY;
-    }
-
-    /**
-     * 构造一个EntityWrapper<T></>
-     *
-     * @param <T>
-     * @return
-     */
-    public static <T> EntityWrapper<T> entityWrapper() {
-        return entityWrapper(null);
-    }
-
-    /**
-     * 构造一个EntityWrapper<T></>
-     *
-     * @param <T>
-     * @return
-     */
-    public static <T> EntityWrapper<T> entityWrapper(T entity) {
-        return new EntityWrapper<>(entity);
-    }
-
-}

+ 4 - 87
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/EntityWrapper.java

@@ -16,21 +16,17 @@
 package com.baomidou.mybatisplus.core.conditions;
 
 
-import com.baomidou.mybatisplus.core.metadata.Column;
-import com.baomidou.mybatisplus.core.metadata.Columns;
-import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
 
 /**
  * <p>
- * Entity 对象封装操作类,定义T-SQL语法
+ * Entity 对象封装操作类
  * </p>
  *
- * @author hubin , yanghu , Dyang , Caratacus
- * @Date 2016-11-7
+ * @author hubin
+ * @Date 2018-05-25
  */
-@SuppressWarnings("serial")
 public class EntityWrapper<T> extends Wrapper<T> {
 
     /**
@@ -75,91 +71,12 @@ public class EntityWrapper<T> extends Wrapper<T> {
         return this;
     }
 
-    /**
-     * <p>
-     * 使用字符串数组封装sqlSelect,便于在不需要指定 AS 的情况下通过实体类自动生成的列静态字段快速组装 sqlSelect,<br/>
-     * 减少手动录入的错误率
-     * </p>
-     *
-     * @param columns 字段
-     * @return
-     */
-    public Wrapper<T> setSqlSelect(String... columns) {
-        StringBuilder builder = new StringBuilder();
-        for (String column : columns) {
-            if (StringUtils.isNotEmpty(column)) {
-                if (builder.length() > 0) {
-                    builder.append(",");
-                }
-                builder.append(column);
-            }
-        }
-        this.sqlSelect = builder.toString();
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用对象封装的setsqlselect
-     * </p>
-     *
-     * @param column 字段
-     * @return
-     */
-    public Wrapper<T> setSqlSelect(Column... column) {
-        if (ArrayUtils.isNotEmpty(column)) {
-            StringBuilder builder = new StringBuilder();
-            for (int i = 0; i < column.length; i++) {
-                if (column[i] != null) {
-                    String col = column[i].getColumn();
-                    String as = column[i].getAs();
-                    if (StringUtils.isEmpty(col)) {
-                        continue;
-                    }
-                    builder.append(col).append(as);
-                    if (i < column.length - 1) {
-                        builder.append(",");
-                    }
-                }
-            }
-            this.sqlSelect = builder.toString();
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用对象封装的setsqlselect
-     * </p>
-     *
-     * @param columns 字段
-     * @return
-     */
-    public Wrapper<T> setSqlSelect(Columns columns) {
-        Column[] columnArray = columns.getColumns();
-        if (ArrayUtils.isNotEmpty(columnArray)) {
-            setSqlSelect(columnArray);
-        }
-        return this;
-    }
-
     /**
      * SQL 片段
      */
     @Override
     public String getSqlSegment() {
-        /*
-         * 无条件
-         */
-        String sqlWhere = sql.toString();
-        if (StringUtils.isEmpty(sqlWhere)) {
-            return null;
-        }
-
-        /*
-         * 根据当前实体判断是否需要将WHERE替换成 AND 增加实体不为空但所有属性为空的情况
-         */
-        return isWhere != null ? (isWhere ? sqlWhere : sqlWhere.replaceFirst("WHERE", AND_OR)) : sqlWhere.replaceFirst("WHERE", AND_OR);
+        return null;
     }
 
 }

+ 1 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/MybatisAbstractSQL.java

@@ -33,6 +33,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  * @author yanghu
  * @Date 2016-08-22
  */
+@Deprecated
 @SuppressWarnings("serial")
 public abstract class MybatisAbstractSQL<T> implements Serializable {
 

+ 1 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/SqlPlus.java

@@ -27,6 +27,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  * @author yanghu , Caratacus , hubin
  * @Date 2016-08-22
  */
+@Deprecated
 @SuppressWarnings("serial")
 public class SqlPlus extends MybatisAbstractSQL<SqlPlus> {
 

+ 2 - 14
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/UpdateWrapper.java

@@ -16,8 +16,6 @@
 package com.baomidou.mybatisplus.core.conditions;
 
 
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-
 /**
  * <p>
  * Entity 对象封装操作类,定义T-SQL语法
@@ -26,7 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  * @author hubin , yanghu , Dyang , Caratacus
  * @Date 2016-11-7
  */
-public class UpdateWrapper<T> extends Wrapper<T> {
+public class UpdateWrapper<T> extends Wrapper {
 
     /**
      * 数据库表映射实体类
@@ -71,18 +69,8 @@ public class UpdateWrapper<T> extends Wrapper<T> {
      */
     @Override
     public String getSqlSegment() {
-        /*
-         * 无条件
-         */
-        String sqlWhere = sql.toString();
-        if (StringUtils.isEmpty(sqlWhere)) {
-            return null;
-        }
 
-        /*
-         * 根据当前实体判断是否需要将WHERE替换成 AND 增加实体不为空但所有属性为空的情况
-         */
-        return isWhere != null ? (isWhere ? sqlWhere : sqlWhere.replaceFirst("WHERE", AND_OR)) : sqlWhere.replaceFirst("WHERE", AND_OR);
+        return null;
     }
 
 }

+ 5 - 1546
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Wrapper.java

@@ -16,1572 +16,31 @@
 package com.baomidou.mybatisplus.core.conditions;
 
 import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import com.baomidou.mybatisplus.core.enums.SqlLike;
-import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
-import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.MapUtils;
-import com.baomidou.mybatisplus.core.toolkit.SerializationUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import com.baomidou.mybatisplus.core.toolkit.TableInfoHelper;
-import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
-import com.baomidou.mybatisplus.core.toolkit.support.Property;
 
 
 /**
  * <p>
- * 条件构造抽象类,定义T-SQL语法
+ * 条件构造抽象类
  * </p>
  *
- * @author hubin , yanghu , Dyang , Caratacus, hcl
- * @Date 2016-11-7
+ * @author hubin
+ * @Date 2018-05-25
  */
 public abstract class Wrapper<T> implements Serializable {
 
-    /**
-     * 占位符
-     */
-    private static final String PLACE_HOLDER = "{%s}";
-
-    private static final String MYBATIS_PLUS_TOKEN = "#{%s.paramNameValuePairs.%s}";
+    // ew.select(User:getName, User:getAge).eq(User:getName, "123");
 
-    private static final String MP_GENERAL_PARAMNAME = "MPGENVAL";
-
-    private static final String DEFAULT_PARAM_ALIAS = "ew";
-    /**
-     * 实现了TSQL语法的SQL实体
-     */
-    protected final SqlPlus sql = new SqlPlus();
-    private final Map<String, Object> paramNameValuePairs = new HashMap<>();
-    private final AtomicInteger paramNameSeq = new AtomicInteger(0);
-    protected String paramAlias = null;
     /**
-     * 自定义是否输出sql为 WHERE OR AND OR OR
-     */
-    protected Boolean isWhere;
-    /**
-     * 拼接WHERE后应该是AND还是ORnull
-     */
-    protected String AND_OR = "AND";
-
-    /**
-     * <p>
-     * 兼容EntityWrapper
-     * </p>
-     *
-     * @return
+     * 实体对象(子类实现)
      */
     public T getEntity() {
         return null;
     }
 
-    /**
-     * 查看where构造是否为空
-     *
-     * @return
-     */
-    public boolean isEmptyOfWhere() {
-        return sql.isEmptyOfWhere();
-    }
-
-    /**
-     * 查看where构造是否不为空
-     *
-     * @return
-     */
-    public boolean isNotEmptyOfWhere() {
-        return !isEmptyOfWhere();
-    }
-
     /**
      * SQL 片段 (子类实现)
      */
     public abstract String getSqlSegment();
 
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder("Wrapper<T>:");
-        String sqlSegment = getSqlSegment();
-        sb.append(replacePlaceholder(sqlSegment));
-        Object entity = getEntity();
-        if (entity != null) {
-            sb.append("\n");
-            sb.append("entity=").append(entity.toString());
-        }
-        return sb.toString();
-    }
-
-    /**
-     * <p>
-     * 替换占位符
-     * </p>
-     *
-     * @param sqlSegment
-     * @return
-     */
-    private String replacePlaceholder(String sqlSegment) {
-        if (StringUtils.isEmpty(sqlSegment)) {
-            return StringUtils.EMPTY;
-        }
-        return sqlSegment.replaceAll("#\\{" + getParamAlias() + ".paramNameValuePairs.MPGENVAL[0-9]+}", "\\?");
-    }
-
-    /**
-     * <p>
-     * 原生占位符sql
-     * </p>
-     *
-     * @return
-     */
-    public String originalSql() {
-        return replacePlaceholder(getSqlSegment());
-    }
-
-    /**
-     * <p>
-     * SQL中WHERE关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").where(id!=null, "id={0}", id);
-     * <p>
-     * 输出:<br>
-     * 如果id=123:  WHERE (NAME='zhangsan' AND id=123)<br>
-     * 如果id=null: WHERE (NAME='zhangsan')
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param sqlWhere  where语句
-     * @param params    参数集
-     * @return this
-     */
-    public Wrapper<T> where(boolean condition, String sqlWhere, Object... params) {
-        if (condition) {
-            sql.WHERE(formatSql(sqlWhere, params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * SQL中WHERE关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").where("id={0}","123");
-     * <p>
-     * 输出: WHERE (NAME='zhangsan' AND id=123)
-     * </p>
-     *
-     * @param sqlWhere where语句
-     * @param params   参数集
-     * @return this
-     */
-    public Wrapper<T> where(String sqlWhere, Object... params) {
-        return where(true, sqlWhere, params);
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field=value"表达式
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> eq(boolean condition, String column, Object params) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s = {0}", column), params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field=value"表达式
-     * </p>
-     *
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> eq(String column, Object params) {
-        return eq(true, column, params);
-    }
-
-    public Wrapper<T> eq(boolean condition, Property<T, ?> func, Object params) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s = {0}", toCol(func)), params));
-        }
-        return this;
-    }
-
-    /**
-     * 为了支持字段重构做出的修改
-     * <p>
-     * 你可以在指定 Wrapper<T> 泛型的前提下这么使用:
-     * <p>
-     * Wrapper<User> wrapper = new EntityWrapper<User>();
-     * wrapper.eq(User::getUserName, "baomidou")
-     * <p>
-     * 改方法会根据规则(比如配置的字段映射、或者下划线规则)将 User::getUserName 转换为对应的数据库字段信息
-     *
-     * @param func   需要转换的 function
-     * @param params 参数信息
-     * @return 返回自身
-     */
-    public Wrapper<T> eq(Property<T, ?> func, Object params) {
-        return eq(true, func, params);
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field <> value"表达式
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> ne(boolean condition, String column, Object params) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s <> {0}", column), params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field <> value"表达式
-     * </p>
-     *
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> ne(String column, Object params) {
-        return ne(true, column, params);
-
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field=value"表达式
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param params
-     * @return
-     */
-    @SuppressWarnings({"rawtypes", "unchecked"})
-    public Wrapper<T> allEq(boolean condition, Map<String, Object> params) {
-        if (condition && MapUtils.isNotEmpty(params)) {
-            Iterator iterator = params.entrySet().iterator();
-            while (iterator.hasNext()) {
-                Map.Entry<String, Object> entry = (Map.Entry<String, Object>) iterator.next();
-                Object value = entry.getValue();
-                if (StringUtils.checkValNotNull(value)) {
-                    sql.WHERE(formatSql(String.format("%s = {0}", entry.getKey()), entry.getValue()));
-                }
-
-            }
-
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field=value"表达式
-     * </p>
-     *
-     * @param params
-     * @return
-     */
-    @SuppressWarnings({"rawtypes", "unchecked"})
-    public Wrapper<T> allEq(Map<String, Object> params) {
-        return allEq(true, params);
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field>value"表达式
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> gt(boolean condition, String column, Object params) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s > {0}", column), params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field>value"表达式
-     * </p>
-     *
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> gt(String column, Object params) {
-        return gt(true, column, params);
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field>=value"表达式
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> ge(boolean condition, String column, Object params) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s >= {0}", column), params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field>=value"表达式
-     * </p>
-     *
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> ge(String column, Object params) {
-        return ge(true, column, params);
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field<value"表达式
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> lt(boolean condition, String column, Object params) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s < {0}", column), params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field<value"表达式
-     * </p>
-     *
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> lt(String column, Object params) {
-        return lt(true, column, params);
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field<=value"表达式
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> le(boolean condition, String column, Object params) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s <= {0}", column), params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 等同于SQL的"field<=value"表达式
-     * </p>
-     *
-     * @param column
-     * @param params
-     * @return
-     */
-    public Wrapper<T> le(String column, Object params) {
-        return le(true, column, params);
-    }
-
-    /**
-     * <p>
-     * AND 连接后续条件
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param sqlAnd    and条件语句
-     * @param params    参数集
-     * @return this
-     */
-    public Wrapper<T> and(boolean condition, String sqlAnd, Object... params) {
-        if (condition) {
-            sql.AND().WHERE(formatSql(sqlAnd, params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * AND 连接后续条件
-     * </p>
-     *
-     * @param sqlAnd and条件语句
-     * @param params 参数集
-     * @return this
-     */
-    public Wrapper<T> and(String sqlAnd, Object... params) {
-        return and(true, sqlAnd, params);
-    }
-
-    /**
-     * <p>
-     * 使用AND连接并换行
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").and("id=11").andNew("statu=1"); 输出: WHERE
-     * (name='zhangsan' AND id=11) AND (statu=1)
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param sqlAnd    AND 条件语句
-     * @param params    参数值
-     * @return this
-     */
-    public Wrapper<T> andNew(boolean condition, String sqlAnd, Object... params) {
-        if (condition) {
-            sql.AND_NEW().WHERE(formatSql(sqlAnd, params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用AND连接并换行
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").and("id=11").andNew("statu=1"); 输出: WHERE
-     * (name='zhangsan' AND id=11) AND (statu=1)
-     * </p>
-     *
-     * @return this
-     */
-    public Wrapper<T> andNew() {
-        sql.AND_NEW();
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用AND连接并换行
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").and("id=11").andNew("statu=1"); 输出: WHERE
-     * (name='zhangsan' AND id=11) AND (statu=1)
-     * </p>
-     *
-     * @param sqlAnd AND 条件语句
-     * @param params 参数值
-     * @return this
-     */
-    public Wrapper<T> andNew(String sqlAnd, Object... params) {
-        return andNew(true, sqlAnd, params);
-    }
-
-    /**
-     * <p>
-     * 使用AND连接并换行
-     * </p>
-     *
-     * @return this
-     */
-    public Wrapper<T> and() {
-        sql.AND();
-        return this;
-    }
-
-    /**
-     * <p>
-     * 左嵌套方法
-     * </p>
-     *
-     * @return this
-     */
-    public Wrapper<T> leftNest() {
-        leftNest(1);
-        return this;
-    }
-
-    /**
-     * <p>
-     * 右嵌套方法
-     * </p>
-     *
-     * @return this
-     */
-    public Wrapper<T> rightNest() {
-        rightNest(1);
-        return this;
-    }
-
-    /**
-     * <p>
-     * 左嵌套方法,一般认为填补mp一个条件中多重嵌套解决方案
-     * </p>
-     *
-     * @param num 嵌套数量
-     * @return this
-     */
-    public Wrapper<T> leftNest(int num) {
-        nest("(", num);
-        return this;
-    }
-
-    /**
-     * <p>
-     * 右嵌套方法,一般认为填补mp一个条件中多重嵌套解决方案
-     * </p>
-     *
-     * @param num 嵌套数量
-     * @return this
-     */
-    public Wrapper<T> rightNest(int num) {
-        nest(")", num);
-        return this;
-    }
-
-    /**
-     * <p>
-     * 嵌套方法,一般认为填补mp一个条件中多重嵌套解决方案
-     * </p>
-     *
-     * @param nest 嵌套字符串 "(" or ")"
-     * @param num  嵌套数量
-     * @return this
-     */
-    private Wrapper<T> nest(String nest, int num) {
-        if (num >= 1) {
-            StringBuilder builder = new StringBuilder(num);
-            for (int i = 0; i < num; i++) {
-                builder.append(nest);
-            }
-            sql.SUPP(builder.toString());
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用OR连接并换行
-     * </p>
-     *
-     * @return this
-     */
-    public Wrapper<T> or() {
-        sql.OR();
-        return this;
-    }
-
-    /**
-     * <p>
-     * 添加OR条件
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param sqlOr     or 条件语句
-     * @param params    参数集
-     * @return this
-     */
-    public Wrapper<T> or(boolean condition, String sqlOr, Object... params) {
-        if (condition) {
-            if (StringUtils.isEmpty(sql.toString())) {
-                AND_OR = "OR";
-            }
-            sql.OR().WHERE(formatSql(sqlOr, params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 添加OR条件
-     * </p>
-     *
-     * @param sqlOr  or 条件语句
-     * @param params 参数集
-     * @return this
-     */
-    public Wrapper<T> or(String sqlOr, Object... params) {
-        return or(true, sqlOr, params);
-    }
-
-    /**
-     * <p>
-     * 使用OR换行,并添加一个带()的新的条件
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").and("id=11").orNew("statu=1"); 输出: WHERE
-     * (name='zhangsan' AND id=11) OR (statu=1)
-     * </p>
-     *
-     * @return this
-     */
-    public Wrapper<T> orNew() {
-        sql.OR_NEW();
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用OR换行,并添加一个带()的新的条件
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").and("id=11").orNew("statu=1"); 输出: WHERE
-     * (name='zhangsan' AND id=11) OR (statu=1)
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param sqlOr     AND 条件语句
-     * @param params    参数值
-     * @return this
-     */
-    public Wrapper<T> orNew(boolean condition, String sqlOr, Object... params) {
-        if (condition) {
-            if (StringUtils.isEmpty(sql.toString())) {
-                AND_OR = "OR";
-            }
-            sql.OR_NEW().WHERE(formatSql(sqlOr, params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用OR换行,并添加一个带()的新的条件
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").and("id=11").orNew("statu=1"); 输出: WHERE
-     * (name='zhangsan' AND id=11) OR (statu=1)
-     * </p>
-     *
-     * @param sqlOr  AND 条件语句
-     * @param params 参数值
-     * @return this
-     */
-    public Wrapper<T> orNew(String sqlOr, Object... params) {
-        return orNew(true, sqlOr, params);
-    }
-
-    /**
-     * <p>
-     * SQL中groupBy关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").groupBy("id,name")
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param columns   SQL 中的 Group by 语句,无需输入 Group By 关键字
-     * @return this
-     */
-    public Wrapper<T> groupBy(boolean condition, String columns) {
-        if (condition) {
-            sql.GROUP_BY(columns);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * SQL中groupBy关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.where("name='zhangsan'").groupBy("id,name")
-     * </p>
-     *
-     * @param columns SQL 中的 Group by 语句,无需输入 Group By 关键字
-     * @return this
-     */
-    public Wrapper<T> groupBy(String columns) {
-        return groupBy(true, columns);
-    }
-
-    /**
-     * <p>
-     * SQL中having关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null")
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param sqlHaving having关键字后面跟随的语句
-     * @param params    参数集
-     * @return EntityWrapper<T>
-     */
-    public Wrapper<T> having(boolean condition, String sqlHaving, Object... params) {
-        if (condition) {
-            sql.HAVING(formatSql(sqlHaving, params));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * SQL中having关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null")
-     * </p>
-     *
-     * @param sqlHaving having关键字后面跟随的语句
-     * @param params    参数集
-     * @return EntityWrapper<T>
-     */
-    public Wrapper<T> having(String sqlHaving, Object... params) {
-        return having(true, sqlHaving, params);
-    }
-
-    /**
-     * <p>
-     * SQL中orderby关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null"
-     * ).orderBy("id,name")
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param columns   SQL 中的 order by 语句,无需输入 Order By 关键字
-     * @return this
-     */
-    public Wrapper<T> orderBy(boolean condition, String columns) {
-        if (condition) {
-            sql.ORDER_BY(columns);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * SQL中orderby关键字跟的条件语句
-     * </p>
-     * <p>
-     * eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null"
-     * ).orderBy("id,name")
-     * </p>
-     *
-     * @param columns SQL 中的 order by 语句,无需输入 Order By 关键字
-     * @return this
-     */
-    public Wrapper<T> orderBy(String columns) {
-        return orderBy(true, columns);
-    }
-
-    /**
-     * <p>
-     * SQL中orderby关键字跟的条件语句,可根据变更动态排序
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param columns   SQL 中的 order by 语句,无需输入 Order By 关键字
-     * @param isAsc     是否为升序
-     * @return this
-     */
-    public Wrapper<T> orderBy(boolean condition, String columns, boolean isAsc) {
-        if (condition && StringUtils.isNotEmpty(columns)) {
-            sql.ORDER_BY(columns + (isAsc ? " ASC" : " DESC"));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * SQL中orderby关键字跟的条件语句,可根据变更动态排序
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param columns   SQL 中的 order by 语句,无需输入 Order By 关键字
-     * @param isAsc     是否为升序
-     * @return this
-     */
-    public Wrapper<T> orderBy(boolean condition, Collection<String> columns, boolean isAsc) {
-        if (condition && CollectionUtils.isNotEmpty(columns)) {
-            for (String column : columns) {
-                orderBy(condition, column, isAsc);
-            }
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * SQL中orderby关键字跟的条件语句,可根据变更动态排序
-     * </p>
-     *
-     * @param columns SQL 中的 order by 语句,无需输入 Order By 关键字
-     * @param isAsc   是否为升序
-     * @return this
-     */
-    public Wrapper<T> orderBy(String columns, boolean isAsc) {
-        return orderBy(true, columns, isAsc);
-    }
-
-    /**
-     * <p>
-     * 批量根据ASC排序
-     * </p>
-     *
-     * @param columns 需要排序的集合
-     * @return this
-     */
-    public Wrapper<T> orderAsc(Collection<String> columns) {
-        return orderBy(true, columns, true);
-    }
-
-    /**
-     * <p>
-     * 批量根据DESC排序
-     * </p>
-     *
-     * @param columns 需要排序的集合
-     * @return this
-     */
-    public Wrapper<T> orderDesc(Collection<String> columns) {
-        return orderBy(true, columns, false);
-    }
-
-    /**
-     * <p>
-     * LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值
-     * @return this
-     */
-    public Wrapper<T> like(boolean condition, String column, String value) {
-        if (condition) {
-            handlerLike(column, value, SqlLike.DEFAULT, false);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值
-     * @return this
-     */
-    public Wrapper<T> like(String column, String value) {
-        return like(true, column, value);
-    }
-
-    /**
-     * <p>
-     * NOT LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值
-     * @return this
-     */
-    public Wrapper<T> notLike(boolean condition, String column, String value) {
-        if (condition) {
-            handlerLike(column, value, SqlLike.DEFAULT, true);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * NOT LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值
-     * @return this
-     */
-    public Wrapper<T> notLike(String column, String value) {
-        return notLike(true, column, value);
-    }
-
-    /**
-     * <p>
-     * 处理LIKE操作
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  like匹配值
-     * @param isNot  是否为NOT LIKE操作
-     */
-    private void handlerLike(String column, String value, SqlLike type, boolean isNot) {
-        if (StringUtils.isNotEmpty(column) && StringUtils.isNotEmpty(value)) {
-            StringBuilder inSql = new StringBuilder();
-            inSql.append(column);
-            if (isNot) {
-                inSql.append(" NOT");
-            }
-            inSql.append(" LIKE {0}");
-            sql.WHERE(formatSql(inSql.toString(), SqlUtils.concatLike(value, type)));
-        }
-    }
-
-    /**
-     * <p>
-     * LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值
-     * @param type
-     * @return this
-     */
-    public Wrapper<T> like(boolean condition, String column, String value, SqlLike type) {
-        if (condition) {
-            handlerLike(column, value, type, false);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值
-     * @param type
-     * @return this
-     */
-    public Wrapper<T> like(String column, String value, SqlLike type) {
-        return like(true, column, value, type);
-    }
-
-    /**
-     * <p>
-     * NOT LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值
-     * @param type
-     * @return this
-     */
-    public Wrapper<T> notLike(boolean condition, String column, String value, SqlLike type) {
-        if (condition) {
-            handlerLike(column, value, type, true);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * NOT LIKE条件语句,value中无需前后%
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值
-     * @param type
-     * @return this
-     */
-    public Wrapper<T> notLike(String column, String value, SqlLike type) {
-        return notLike(true, column, value, type);
-    }
-
-    /**
-     * <p>
-     * is not null 条件
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param columns   字段名称。多个字段以逗号分隔。
-     * @return this
-     */
-    public Wrapper<T> isNotNull(boolean condition, String columns) {
-        if (condition) {
-            sql.IS_NOT_NULL(columns);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * is not null 条件
-     * </p>
-     *
-     * @param columns 字段名称。多个字段以逗号分隔。
-     * @return this
-     */
-    public Wrapper<T> isNotNull(String columns) {
-        return isNotNull(true, columns);
-    }
-
-    /**
-     * <p>
-     * is null 条件
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param columns   字段名称。多个字段以逗号分隔。
-     * @return this
-     */
-    public Wrapper<T> isNull(boolean condition, String columns) {
-        if (condition) {
-            sql.IS_NULL(columns);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * is null 条件
-     * </p>
-     *
-     * @param columns 字段名称。多个字段以逗号分隔。
-     * @return this
-     */
-    public Wrapper<T> isNull(String columns) {
-        return isNull(true, columns);
-    }
-
-    /**
-     * <p>
-     * EXISTS 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param value     匹配值
-     * @return this
-     */
-    public Wrapper<T> exists(boolean condition, String value) {
-        if (condition) {
-            sql.EXISTS(value);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * EXISTS 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param value 匹配值
-     * @return this
-     */
-    public Wrapper<T> exists(String value) {
-        return exists(true, value);
-    }
-
-    /**
-     * <p>
-     * NOT EXISTS条件语句
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param value     匹配值
-     * @return this
-     */
-    public Wrapper<T> notExists(boolean condition, String value) {
-        if (condition) {
-            sql.NOT_EXISTS(value);
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * NOT EXISTS条件语句
-     * </p>
-     *
-     * @param value 匹配值
-     * @return this
-     */
-    public Wrapper<T> notExists(String value) {
-        return notExists(true, value);
-    }
-
-    /**
-     * <p>
-     * IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     逗号拼接的字符串
-     * @return this
-     */
-    public Wrapper<T> in(boolean condition, String column, String value) {
-        if (condition && StringUtils.isNotEmpty(value)) {
-            in(column, StringUtils.splitWorker(value, ",", -1, false));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  逗号拼接的字符串
-     * @return this
-     */
-    public Wrapper<T> in(String column, String value) {
-        return in(true, column, value);
-    }
-
-    /**
-     * <p>
-     * NOT IN条件语句
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     逗号拼接的字符串
-     * @return this
-     */
-    public Wrapper<T> notIn(boolean condition, String column, String value) {
-        if (condition && StringUtils.isNotEmpty(value)) {
-            notIn(column, StringUtils.splitWorker(value, ",", -1, false));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * NOT IN条件语句
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  逗号拼接的字符串
-     * @return this
-     */
-    public Wrapper<T> notIn(String column, String value) {
-        return notIn(true, column, value);
-    }
-
-    /**
-     * <p>
-     * IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值 集合
-     * @return this
-     */
-    public Wrapper<T> in(boolean condition, String column, Collection<?> value) {
-        if (condition && CollectionUtils.isNotEmpty(value)) {
-            sql.WHERE(formatSql(inExpression(column, value, false), value.toArray()));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值 集合
-     * @return this
-     */
-    public Wrapper<T> in(String column, Collection<?> value) {
-        return in(true, column, value);
-    }
-
-    /**
-     * <p>
-     * NOT IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值 集合
-     * @return this
-     */
-    public Wrapper<T> notIn(boolean condition, String column, Collection<?> value) {
-        if (condition && CollectionUtils.isNotEmpty(value)) {
-            sql.WHERE(formatSql(inExpression(column, value, true), value.toArray()));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * NOT IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值 集合
-     * @return this
-     */
-    public Wrapper<T> notIn(String column, Collection<?> value) {
-        return notIn(true, column, value);
-    }
-
-    /**
-     * <p>
-     * IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值 object数组
-     * @return this
-     */
-    public Wrapper<T> in(boolean condition, String column, Object[] value) {
-        if (condition && ArrayUtils.isNotEmpty(value)) {
-            sql.WHERE(formatSql(inExpression(column, Arrays.asList(value), false), value));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值 object数组
-     * @return this
-     */
-    public Wrapper<T> in(String column, Object[] value) {
-        return in(true, column, value);
-    }
-
-    /**
-     * <p>
-     * NOT IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param value     匹配值 object数组
-     * @return this
-     */
-    public Wrapper<T> notIn(boolean condition, String column, Object... value) {
-        if (condition && ArrayUtils.isNotEmpty(value)) {
-            sql.WHERE(formatSql(inExpression(column, Arrays.asList(value), true), value));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * NOT IN 条件语句,目前适配mysql及oracle
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  匹配值 object数组
-     * @return this
-     */
-    public Wrapper<T> notIn(String column, Object... value) {
-        return notIn(true, column, value);
-    }
-
-    /**
-     * <p>
-     * 获取in表达式
-     * </p>
-     *
-     * @param column 字段名称
-     * @param value  集合
-     * @param isNot  是否为NOT IN操作
-     */
-    private String inExpression(String column, Collection<?> value, boolean isNot) {
-        if (StringUtils.isNotEmpty(column) && CollectionUtils.isNotEmpty(value)) {
-            StringBuilder inSql = new StringBuilder();
-            inSql.append(column);
-            if (isNot) {
-                inSql.append(" NOT");
-            }
-            inSql.append(" IN ");
-            inSql.append("(");
-            int size = value.size();
-            for (int i = 0; i < size; i++) {
-                inSql.append(String.format(PLACE_HOLDER, i));
-                if (i + 1 < size) {
-                    inSql.append(",");
-                }
-            }
-            inSql.append(")");
-            return inSql.toString();
-        }
-        return null;
-    }
-
-    /**
-     * <p>
-     * betwwee 条件语句
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param val1
-     * @param val2
-     * @return this
-     */
-    public Wrapper<T> between(boolean condition, String column, Object val1, Object val2) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s BETWEEN {0} AND {1}", column), val1, val2));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * betwwee 条件语句
-     * </p>
-     *
-     * @param column 字段名称
-     * @param val1
-     * @param val2
-     * @return this
-     */
-    public Wrapper<T> between(String column, Object val1, Object val2) {
-        return between(true, column, val1, val2);
-    }
-
-    /**
-     * <p>
-     * NOT betwwee 条件语句
-     * </p>
-     *
-     * @param condition 拼接的前置条件
-     * @param column    字段名称
-     * @param val1
-     * @param val2
-     * @return this
-     */
-    public Wrapper<T> notBetween(boolean condition, String column, Object val1, Object val2) {
-        if (condition) {
-            sql.WHERE(formatSql(String.format("%s NOT BETWEEN {0} AND {1}", column), val1, val2));
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * NOT betwwee 条件语句
-     * </p>
-     *
-     * @param column 字段名称
-     * @param val1
-     * @param val2
-     * @return this
-     */
-    public Wrapper<T> notBetween(String column, Object val1, Object val2) {
-        return notBetween(true, column, val1, val2);
-
-    }
-
-    /**
-     * <p>
-     * 为了兼容之前的版本,可使用where()或and()替代
-     * </p>
-     *
-     * @param sqlWhere where sql部分
-     * @param params   参数集
-     * @return this
-     */
-    public Wrapper<T> addFilter(String sqlWhere, Object... params) {
-        return and(sqlWhere, params);
-    }
-
-    /**
-     * <p>
-     * 根据判断条件来添加条件语句部分 使用 andIf() 替代
-     * </p>
-     * <p>
-     * eg: ew.filterIfNeed(false,"name='zhangsan'").where("name='zhangsan'")
-     * .filterIfNeed(true,"id={0}",22)
-     * <p>
-     * 输出: WHERE (name='zhangsan' AND id=22)
-     * </p>
-     *
-     * @param need     是否需要添加该条件
-     * @param sqlWhere 条件语句
-     * @param params   参数集
-     * @return this
-     */
-    public Wrapper<T> addFilterIfNeed(boolean need, String sqlWhere, Object... params) {
-        return need ? where(sqlWhere, params) : this;
-    }
-
-    /**
-     * <p>
-     * 格式化SQL
-     * </p>
-     *
-     * @param sqlStr SQL语句部分
-     * @param params 参数集
-     * @return this
-     */
-    protected String formatSql(String sqlStr, Object... params) {
-        return formatSqlIfNeed(true, sqlStr, params);
-    }
-
-    /**
-     * <p>
-     * 根据需要格式化SQL<BR>
-     * <BR>
-     * Format SQL for methods: EntityWrapper<T>.where/and/or...("name={0}", value);
-     * ALL the {<b>i</b>} will be replaced with #{MPGENVAL<b>i</b>}<BR>
-     * <BR>
-     * ew.where("sample_name=<b>{0}</b>", "haha").and("sample_age &gt;<b>{0}</b>
-     * and sample_age&lt;<b>{1}</b>", 18, 30) <b>TO</b>
-     * sample_name=<b>#{MPGENVAL1}</b> and sample_age&gt;#<b>{MPGENVAL2}</b> and
-     * sample_age&lt;<b>#{MPGENVAL3}</b><BR>
-     * </p>
-     *
-     * @param need   是否需要格式化
-     * @param sqlStr SQL语句部分
-     * @param params 参数集
-     * @return this
-     */
-    protected String formatSqlIfNeed(boolean need, String sqlStr, Object... params) {
-        if (!need || StringUtils.isEmpty(sqlStr)) {
-            return null;
-        }
-        // #200
-        if (ArrayUtils.isNotEmpty(params)) {
-            for (int i = 0; i < params.length; ++i) {
-                String genParamName = MP_GENERAL_PARAMNAME + paramNameSeq.incrementAndGet();
-                sqlStr = sqlStr.replace(String.format(PLACE_HOLDER, i),
-                    String.format(MYBATIS_PLUS_TOKEN, getParamAlias(), genParamName));
-                paramNameValuePairs.put(genParamName, params[i]);
-            }
-        }
-        return sqlStr;
-    }
-
-    /**
-     * <p>
-     * 自定义是否输出sql开头为 `WHERE` OR `AND` OR `OR`
-     * </p>
-     *
-     * @param bool
-     * @return this
-     */
-    public Wrapper<T> isWhere(Boolean bool) {
-        this.isWhere = bool;
-        return this;
-    }
-
-    /**
-     * <p>
-     * 手动把sql拼接到最后(有sql注入的风险,请谨慎使用)
-     * </p>
-     *
-     * @param limit
-     * @return this
-     */
-    public Wrapper<T> last(String limit) {
-        sql.LAST(limit);
-        return this;
-    }
-
-    /**
-     * Fix issue 200.
-     *
-     * @return
-     * @since 2.0.3
-     */
-    public Map<String, Object> getParamNameValuePairs() {
-        return paramNameValuePairs;
-    }
-
-    public String getParamAlias() {
-        return StringUtils.isEmpty(paramAlias) ? DEFAULT_PARAM_ALIAS : paramAlias;
-    }
-
-    /**
-     * <p>
-     * 参数别名设置,初始化时优先设置该值、重复设置异常
-     * </p>
-     *
-     * @param paramAlias 参数别名
-     * @return
-     */
-    public Wrapper<T> setParamAlias(String paramAlias) {
-        if (StringUtils.isNotEmpty(getSqlSegment())) {
-            throw new MybatisPlusException("Error: Please call this method when initializing!");
-        }
-        if (StringUtils.isNotEmpty(this.paramAlias)) {
-            throw new MybatisPlusException("Error: Please do not call the method repeatedly!");
-        }
-        this.paramAlias = paramAlias;
-        return this;
-    }
-
-    /**
-     * 是否为空
-     */
-    public boolean isEmpty() {
-        return sql.isEmptyOfWhere();
-    }
-
-    public static <T> Wrapper<T> getInstance() {
-        return new Wrapper<T>() {
-            @Override
-            public String getSqlSegment() {
-                return null;
-            }
-        };
-    }
-
-    /**
-     * <p>
-     * 克隆本身 fixed github issues/241
-     * </p>
-     */
-    @Override
-    public Wrapper<T> clone() {
-        return SerializationUtils.clone(this);
-    }
-
-    /**
-     * @param func function
-     * @return 返回从 function 中解析出的 column
-     */
-    protected String toCol(Property<T, ?> func) {
-        return TableInfoHelper.toColumn(func);
-    }
 }
 

+ 9 - 9
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/sql/SqlHelper.java

@@ -197,14 +197,14 @@ public class SqlHelper {
             wrapper = new EntityWrapper<>();
         }
         // 排序 fixed gitee issues/IHF7N
-        if (page.isOpenSort() && page.isSearchCount()) {
-            wrapper.orderAsc(page.getAscs());
-            wrapper.orderDesc(page.getDescs());
-        }
-        // MAP 参数查询
-        if (MapUtils.isNotEmpty(page.getCondition())) {
-            wrapper.allEq(page.getCondition());
-        }
+//        if (page.isOpenSort() && page.isSearchCount()) {
+//            wrapper.orderAsc(page.getAscs());
+//            wrapper.orderDesc(page.getDescs());
+//        }
+//        // MAP 参数查询
+//        if (MapUtils.isNotEmpty(page.getCondition())) {
+//            wrapper.allEq(page.getCondition());
+//        }
         return wrapper;
     }
 
@@ -217,7 +217,7 @@ public class SqlHelper {
      * @return
      */
     public static boolean isEmptyOfWrapper(Wrapper<?> wrapper) {
-        return null == wrapper || wrapper.isEmpty();
+        return null == wrapper;// || wrapper.isEmpty();
     }
 
     /**

+ 1 - 1
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/Main.java

@@ -9,7 +9,7 @@ import java.time.LocalDate;
 public class Main {
 
     public static void main(String[] args) {
-        columnPrefix();
+        query();
     }
 
     public static void query() {

+ 11 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/ISqlSegment.java

@@ -0,0 +1,11 @@
+package com.baomidou.mybatisplus.core.test.query;
+
+
+public interface ISqlSegment {
+
+    /**
+     * SQL 片段
+     */
+   String sqlSegment();
+
+}

+ 12 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/Keywords.java

@@ -0,0 +1,12 @@
+package com.baomidou.mybatisplus.core.test.query;
+
+
+public enum Keywords implements ISqlSegment {
+
+    AND, OR;
+
+    @Override
+    public String sqlSegment() {
+        return this.toString();
+    }
+}

+ 83 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/Query.java

@@ -0,0 +1,83 @@
+package com.baomidou.mybatisplus.core.test.query;
+
+import com.baomidou.mybatisplus.core.test.query.clause.*;
+import com.baomidou.mybatisplus.core.test.query.predicate.*;
+import com.baomidou.mybatisplus.core.test.query.struct.Statement;
+
+import java.util.function.Function;
+
+
+public class Query implements ISqlSegment {
+
+   private final Statement statement;
+
+   public Query() {
+      this.statement = new Statement();
+   }
+
+   /**
+    * Helper method to enqueue stringable and return self
+    * @param stringable to enqueue
+    * @return this
+    */
+   private Query add(ISqlSegment stringable) {
+      statement.enqueue(stringable);
+      return this;
+   }
+
+   /**
+    * SELECT column(s)
+    * @param columns column or columns to select
+    * @return this
+    */
+   public Query select(String... columns) {
+      return add(new Select(columns));
+   }
+
+   /**
+    * SELECT table(s)
+    * @param tables table or tables from which to select
+    * @return this
+    */
+   public Query from(String... tables) {
+      return add(new From(tables));
+   }
+
+   /**
+    * FROM table JOIN(s)
+    * @param table from which to select
+    * @param joins function to populate join clauses
+    * @return this
+    */
+   public Query from(String table, Function<Table, Table> joins) {
+      From from = new From(new String[]{ table });
+      from.joins(joins.apply(new Table()));
+      return add(from);
+   }
+
+   /**
+    * WHERE expression
+    * @param expression to
+    * @return this
+    */
+   public Query where(String expression) {
+      Where where = new Where(new Condition().apply(expression));
+      return add(where);
+   }
+
+   /**
+    * WHERE expression [and, or]
+    * @param condition function to populate where predicate
+    * @return this
+    */
+   public Query where(String expression, Function<Condition, Condition> condition) {
+      Where where = new Where(condition
+         .apply(new Condition().apply(expression)));
+      return add(where);
+   }
+
+    @Override
+    public String sqlSegment() {
+        return statement.sqlSegment();
+   }
+}

+ 103 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/QueryTest.java

@@ -0,0 +1,103 @@
+package com.baomidou.mybatisplus.core.test.query;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+public class QueryTest {
+
+    private void log(String message) {
+        System.out.println(message);
+    }
+
+    @Test
+    public void test() {
+        String sql = new Query()
+            .select("b.*")
+            .from("bunnies b")
+            .where("b.age > 18", condition ->
+                condition.and("b.type = 'rabid'")
+                    .and("b.abc=12"))
+            .sqlSegment();
+
+        log(sql);
+    }
+
+    @Test
+    public void testBunnies() {
+
+        String sql = new Query()
+            .select("*")
+            .from("bunnies")
+            .sqlSegment();
+
+        log(sql);
+        assertEquals("SELECT * FROM bunnies", sql);
+    }
+
+    @Test
+    public void testCrazyManlyBunnies() {
+
+        String sql = new Query()
+            .select("b.*")
+            .from("bunnies b")
+            .where("b.age > 18", condition ->
+                condition.and("b.type = 'rabid'"))
+            .sqlSegment();
+
+        log(sql);
+        assertEquals("SELECT b.* FROM bunnies b WHERE b.age > 18 AND b.type = 'rabid'", sql);
+    }
+
+    @Test
+    public void testLigers() {
+
+        String sql = new Query()
+            .select("t.id", "l.id")
+            .from("tigers t", table ->
+                table.innerJoin("lions l").on("t.lion_id = l.id"))
+            .sqlSegment();
+
+        log(sql);
+        assertEquals("SELECT t.id, l.id FROM tigers t INNER JOIN lions l ON t.lion_id = l.id", sql);
+    }
+
+    class Sloth {
+
+        private Integer slownessLevel;
+
+        public Sloth(Integer slownessLevel) {
+            this.slownessLevel = slownessLevel;
+        }
+
+        public String repeat(String message) {
+
+            StringBuilder toRepeat = new StringBuilder();
+            char[] chars = message.toCharArray();
+
+            for (char aChar : chars)
+                if (aChar == ' ') toRepeat.append(aChar);
+                else for (int j = 0; j < slownessLevel; j++)
+                    toRepeat.append(aChar);
+
+            return toRepeat.toString();
+        }
+    }
+
+    @Test
+    public void testSpecificSloth() {
+
+        String sql = new Query()
+            .select("s.*")
+            .from("sloths s", "slowness n")
+            .where("s.slowness_id = n.id", condition ->
+                condition.and(nested ->
+                    nested.apply("s.name = 'Kristen Bell'").or("n.level = 1.5")))
+            .sqlSegment();
+
+        log(sql);
+        assertEquals("SELECT s.* FROM sloths s, slowness n WHERE s.slowness_id = n.id AND ( s.name = 'Kristen Bell' OR n.level = 1.5 )", sql);
+    }
+
+}

+ 19 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Column.java

@@ -0,0 +1,19 @@
+package com.baomidou.mybatisplus.core.test.query.clause;
+
+
+public class Column {
+
+   private String name;
+
+   public Column(String name) {
+      this.name = name;
+   }
+
+   public Column eq(String anotherColumn) {
+      return this;
+   }
+
+   public Column greaterThan(String anotherColumn) {
+      return this;
+   }
+}

+ 36 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/From.java

@@ -0,0 +1,36 @@
+package com.baomidou.mybatisplus.core.test.query.clause;
+
+
+import static java.lang.String.format;
+import static java.lang.String.join;
+
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+import com.baomidou.mybatisplus.core.test.query.predicate.Table;
+
+
+public class From implements ISqlSegment {
+
+   private String[] tables;
+   private Table table;
+
+   public From(String[] tables) {
+      this.tables = tables;
+   }
+
+   public void joins(Table table) {
+      this.table = table;
+   }
+
+    @Override
+    public String sqlSegment() {
+      String sql = format("FROM %s", join(", ", (CharSequence[]) tables));
+
+      if (table != null) {
+         sql = sql
+            .concat(" ")
+            .concat(table.sqlSegment());
+      }
+
+      return sql;
+   }
+}

+ 41 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Join.java

@@ -0,0 +1,41 @@
+package com.baomidou.mybatisplus.core.test.query.clause;
+
+import static java.lang.String.format;
+
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+
+
+public class Join implements ISqlSegment {
+
+    public enum JoinType {
+
+        DEFAULT,
+        INNER,
+        LEFT_OUTER,
+        RIGHT_OUTER,
+        FULL_OUTER,
+        CROSS;
+
+        protected String toSQLString() {
+
+            if (this == DEFAULT) {
+                return "JOIN";
+            } else {
+                return format("%s %s", this.toString(), "JOIN");
+            }
+        }
+    }
+
+    private String table;
+    private JoinType joinType;
+
+    public Join(String table, JoinType type) {
+        this.table = table;
+        this.joinType = type;
+    }
+
+    @Override
+    public String sqlSegment() {
+        return format("%s %s", joinType.toSQLString(), table);
+    }
+}

+ 20 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Select.java

@@ -0,0 +1,20 @@
+package com.baomidou.mybatisplus.core.test.query.clause;
+
+import static java.lang.String.format;
+
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+
+
+public class Select implements ISqlSegment {
+
+    private String[] columns;
+
+    public Select(String[] columns) {
+        this.columns = columns;
+    }
+
+    @Override
+    public String sqlSegment() {
+        return format("SELECT %s", String.join(", ", (CharSequence[]) columns));
+    }
+}

+ 19 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/clause/Where.java

@@ -0,0 +1,19 @@
+package com.baomidou.mybatisplus.core.test.query.clause;
+
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+import com.baomidou.mybatisplus.core.test.query.predicate.Condition;
+
+
+public class Where implements ISqlSegment {
+
+   private Condition condition;
+
+   public Where(Condition condition) {
+      this.condition = condition;
+   }
+
+    @Override
+    public String sqlSegment() {
+        return String.format("WHERE %s", condition.sqlSegment());
+   }
+}

+ 58 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/predicate/Condition.java

@@ -0,0 +1,58 @@
+package com.baomidou.mybatisplus.core.test.query.predicate;
+
+import com.baomidou.mybatisplus.core.test.query.Keywords;
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static com.baomidou.mybatisplus.core.test.query.Keywords.AND;
+import static com.baomidou.mybatisplus.core.test.query.Keywords.OR;
+
+
+public class Condition implements ISqlSegment {
+
+    List<ISqlSegment> expression = new ArrayList<>();
+
+    public Condition apply(String condition) {
+        expression.add(() -> condition);
+        return this;
+    }
+
+    public Condition and(String condition) {
+        expression.add(AND);
+        expression.add(() -> condition);
+        return this;
+    }
+
+    public Condition and(Function<Condition, Condition> condition) {
+        return addNestedCondition(condition, AND);
+    }
+
+    public Condition or(String condition) {
+        expression.add(OR);
+        expression.add(() -> condition);
+        return this;
+    }
+
+    public Condition or(Function<Condition, Condition> condition) {
+        return addNestedCondition(condition, OR);
+    }
+
+    private Condition addNestedCondition(Function<Condition, Condition> condition, Keywords keyword) {
+        expression.add(keyword);
+        expression.add(() -> "(");
+        expression.add(condition.apply(new Condition()));
+        expression.add(() -> ")");
+        return this;
+    }
+
+    @Override
+    public String sqlSegment() {
+        return String.join(" ", expression.stream()
+            .map(ISqlSegment::sqlSegment)
+            .collect(Collectors.toList()));
+    }
+}

+ 18 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/predicate/On.java

@@ -0,0 +1,18 @@
+package com.baomidou.mybatisplus.core.test.query.predicate;
+
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+
+
+public class On implements ISqlSegment {
+
+    private String criteria;
+
+    public On(String criteria) {
+        this.criteria = criteria;
+    }
+
+    @Override
+    public String sqlSegment() {
+        return String.format("ON %s", criteria);
+    }
+}

+ 100 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/predicate/Table.java

@@ -0,0 +1,100 @@
+package com.baomidou.mybatisplus.core.test.query.predicate;
+
+import static java.util.stream.Collectors.toList;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+import com.baomidou.mybatisplus.core.test.query.clause.Join;
+
+
+public class Table implements ISqlSegment {
+
+    List<ISqlSegment> stringables = new ArrayList<>();
+
+    /**
+     * INNER JOIN table
+     *
+     * @param table table to join
+     * @return this
+     */
+    public Table innerJoin(String table) {
+        stringables.add(new Join(table, Join.JoinType.INNER));
+        return this;
+    }
+
+    /**
+     * CROSS JOIN table
+     *
+     * @param table table to join
+     * @return this
+     */
+    public Table crossJoin(String table) {
+        stringables.add(new Join(table, Join.JoinType.CROSS));
+        return this;
+    }
+
+    /**
+     * JOIN table
+     *
+     * @param table table to join
+     * @return this
+     */
+    public Table join(String table) {
+        stringables.add(new Join(table, Join.JoinType.DEFAULT));
+        return this;
+    }
+
+    /**
+     * LEFT OUTER JOIN table
+     *
+     * @param table table to join
+     * @return this
+     */
+    public Table leftOuterJoin(String table) {
+        stringables.add(new Join(table, Join.JoinType.LEFT_OUTER));
+        return this;
+    }
+
+    /**
+     * RIGHT OUTER JOIN table
+     *
+     * @param table table to join
+     * @return this
+     */
+    public Table rightOuterJoin(String table) {
+        stringables.add(new Join(table, Join.JoinType.RIGHT_OUTER));
+        return this;
+    }
+
+    /**
+     * FULL OUTER JOIN table
+     *
+     * @param table table to join
+     * @return this
+     */
+    public Table fullOuterJoin(String table) {
+        stringables.add(new Join(table, Join.JoinType.FULL_OUTER));
+        return this;
+    }
+
+    /**
+     * ON expression
+     *
+     * @param expression expression on which to join
+     * @return this
+     */
+    public Table on(String expression) {
+        stringables.add(new On(expression));
+        return this;
+    }
+
+    @Override
+    public String sqlSegment() {
+        return String.join(" ", stringables
+            .stream()
+            .map(ISqlSegment::sqlSegment)
+            .collect(toList()));
+    }
+}

+ 6 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/struct/SimpleQueue.java

@@ -0,0 +1,6 @@
+package com.baomidou.mybatisplus.core.test.query.struct;
+
+
+public interface SimpleQueue<T> {
+   void enqueue(T element);
+}

+ 30 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/query/struct/Statement.java

@@ -0,0 +1,30 @@
+package com.baomidou.mybatisplus.core.test.query.struct;
+
+import static java.util.stream.Collectors.toList;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+
+import com.baomidou.mybatisplus.core.test.query.ISqlSegment;
+
+
+public class Statement implements SimpleQueue<ISqlSegment>, ISqlSegment {
+
+    private Deque<ISqlSegment> deque;
+
+    public Statement() {
+        this.deque = new ArrayDeque<>();
+    }
+
+    @Override
+    public void enqueue(ISqlSegment stringable) {
+        deque.add(stringable);
+    }
+
+    @Override
+    public String sqlSegment() {
+        return String.join(" ", deque.stream()
+            .map(ISqlSegment::sqlSegment)
+            .collect(toList()));
+    }
+}

+ 0 - 6
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/test/GlobalConfigurationTest.java

@@ -25,18 +25,12 @@ import org.apache.ibatis.session.RowBounds;
 import org.apache.ibatis.session.SqlSession;
 import org.junit.Assert;
 
-import com.baomidou.mybatisplus.core.conditions.Condition;
 import com.baomidou.mybatisplus.core.conditions.EntityWrapper;
 import com.baomidou.mybatisplus.extension.test.mysql.entity.NotPK;
 import com.baomidou.mybatisplus.extension.test.mysql.entity.Test;
 import com.baomidou.mybatisplus.extension.test.mysql.mapper.NotPKMapper;
 import com.baomidou.mybatisplus.extension.test.mysql.mapper.RoleMapper;
 import com.baomidou.mybatisplus.extension.test.mysql.mapper.TestMapper;
-import com.baomidou.mybatisplus.extension.test.mysql.entity.NotPK;
-import com.baomidou.mybatisplus.extension.test.mysql.entity.Test;
-import com.baomidou.mybatisplus.extension.test.mysql.mapper.NotPKMapper;
-import com.baomidou.mybatisplus.extension.test.mysql.mapper.RoleMapper;
-import com.baomidou.mybatisplus.extension.test.mysql.mapper.TestMapper;
 
 /**
  * <p>

+ 0 - 1
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/test/mysql/LogicDeleteTest.java

@@ -22,7 +22,6 @@ import java.util.Map;
 import org.apache.ibatis.session.SqlSession;
 import org.junit.Test;
 
-import com.baomidou.mybatisplus.core.conditions.Condition;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.test.CrudTest;