|
@@ -13,12 +13,7 @@
|
|
|
* License for the specific language governing permissions and limitations under
|
|
|
* the License.
|
|
|
*/
|
|
|
-package com.baomidou.mybatisplus.mapper;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.EntityWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.sql.SqlHelper;
|
|
|
+package com.baomidou.mybatisplus.core.conditions;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -29,7 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.sql.SqlHelper;
|
|
|
* @date 2016-11-7
|
|
|
*/
|
|
|
@SuppressWarnings({"rawtypes", "serial"})
|
|
|
-public class Condition extends Wrapper {
|
|
|
+public abstract class Condition {
|
|
|
|
|
|
/**
|
|
|
* 构建一个Empty条件构造 避免传递参数使用null
|
|
@@ -37,52 +32,33 @@ public class Condition extends Wrapper {
|
|
|
public static final Wrapper EMPTY = Wrapper.getInstance();
|
|
|
|
|
|
/**
|
|
|
- * 获取实例
|
|
|
- */
|
|
|
- public static Condition create() {
|
|
|
- return new Condition();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * SQL 片段
|
|
|
+ * 构造一个空的Wrapper<T></>
|
|
|
+ *
|
|
|
+ * @param <T>
|
|
|
+ * @return
|
|
|
*/
|
|
|
- @Override
|
|
|
- public String getSqlSegment() {
|
|
|
- if (SqlHelper.isEmptyOfWrapper(this)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- /*
|
|
|
- * 无条件
|
|
|
- */
|
|
|
- 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);
|
|
|
-
|
|
|
+ public static <T> Wrapper<T> empty() {
|
|
|
+ return (Wrapper<T>) EMPTY;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 构造一个空的Wrapper<T></>
|
|
|
+ * 构造一个EntityWrapper<T></>
|
|
|
*
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
- public static <T> Wrapper<T> empty() {
|
|
|
- return (Wrapper<T>) EMPTY;
|
|
|
+ public static <T> EntityWrapper<T> entityWrapper() {
|
|
|
+ return entityWrapper(null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 构造一个Wrapper<T></>
|
|
|
+ * 构造一个EntityWrapper<T></>
|
|
|
*
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
- public static <T> Wrapper<T> wrapper() {
|
|
|
- return (Wrapper<T>) new EntityWrapper<>();
|
|
|
+ public static <T> EntityWrapper<T> entityWrapper(T entity) {
|
|
|
+ return new EntityWrapper<>(entity);
|
|
|
}
|
|
|
|
|
|
}
|