瀏覽代碼

电脑没电,<标记>明天优化IService

Caratacus 6 年之前
父節點
當前提交
b3dd91b3ed

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

@@ -24,8 +24,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  * </p>
  *
  * @author hubin
+ * @see Wrappers
  * @since 2018-09-01
  */
+@Deprecated
 public class Condition {
 
     /**
@@ -35,11 +37,21 @@ public class Condition {
      * <p>
      * 示例:Condition.<User>create().eq("id", 1)
      * </p>
+     *
+     * @see Wrappers#query()
      */
+    @Deprecated
     public static <T> QueryWrapper<T> create() {
         return new QueryWrapper<>();
     }
 
+    /**
+     * @param entity
+     * @param <T>
+     * @return
+     * @see Wrappers#query()
+     */
+    @Deprecated
     public static <T> QueryWrapper<T> create(T entity) {
         return new QueryWrapper<>(entity);
     }
@@ -51,11 +63,21 @@ public class Condition {
      * <p>
      * 示例:Condition.<User>lambda().eq(User::getId, 1)
      * </p>
+     *
+     * @see Wrappers#query(Object)
      */
+    @Deprecated
     public static <T> LambdaQueryWrapper<T> lambda() {
         return new LambdaQueryWrapper<>();
     }
 
+    /**
+     * @param entity
+     * @param <T>
+     * @return
+     * @see Wrappers#query(Object)
+     */
+    @Deprecated
     public static <T> LambdaQueryWrapper<T> lambda(T entity) {
         return new LambdaQueryWrapper<>(entity);
     }

+ 119 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/EmptyWrapper.java

@@ -0,0 +1,119 @@
+package com.baomidou.mybatisplus.core.conditions;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
+
+/**
+ * <p>
+ * EmptyWrapper
+ * </p>
+ *
+ * @author Caratacus
+ */
+@SuppressWarnings("serial")
+public class EmptyWrapper<T> extends QueryWrapper<T> implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public T getEntity() {
+        return null;
+    }
+
+    @Override
+    public String getSqlSelect() {
+        return null;
+    }
+
+    @Override
+    public String getSqlSet() {
+        return null;
+    }
+
+    @Override
+    public MergeSegments getExpression() {
+        return null;
+    }
+
+    @Override
+    public boolean isEmptyOfWhere() {
+        return true;
+    }
+
+    @Override
+    public boolean isEmptyOfNormal() {
+        return true;
+    }
+
+    @Override
+    public boolean nonEmptyOfEntity() {
+        return !isEmptyOfEntity();
+    }
+
+    @Override
+    public boolean isEmptyOfEntity() {
+        return true;
+    }
+
+    public EmptyWrapper<T> setEntity(T entity) {
+        throw new UnsupportedOperationException();
+    }
+
+    protected void initEntityClass() {
+    }
+
+    protected Class<T> getCheckEntityClass() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public EmptyWrapper<T> last(boolean condition, String lastSql) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    protected EmptyWrapper<T> doIt(boolean condition, ISqlSegment... sqlSegments) {
+        throw new UnsupportedOperationException();
+
+    }
+
+    @Override
+    public String getParamAlias() {
+        return super.getParamAlias();
+    }
+
+    @Override
+    public String getSqlSegment() {
+        return null;
+    }
+
+
+    @Override
+    public Map<String, Object> getParamNameValuePairs() {
+        return Collections.emptyMap();
+    }
+
+    @Override
+    protected String columnsToString(String... columns) {
+        return null;
+    }
+
+    public EmptyWrapper() {
+    }
+
+    @Override
+    protected String columnToString(String column) {
+        return null;
+    }
+
+    @Override
+    protected EmptyWrapper<T> instance(AtomicInteger paramNameSeq, Map<String, Object> paramNameValuePairs) {
+        throw new UnsupportedOperationException();
+    }
+
+}

+ 72 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Wrappers.java

@@ -0,0 +1,72 @@
+package com.baomidou.mybatisplus.core.conditions;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+
+/**
+ * <p>
+ * Wrapper 条件构造
+ * </p>
+ *
+ * @author Caratacus
+ */
+public class Wrappers implements Serializable {
+
+    private static final QueryWrapper emptyWrapper = new EmptyWrapper<>();
+
+    /**
+     * 获取QueryWrapper
+     *
+     * @param <T>
+     * @return
+     */
+    public static <T> QueryWrapper<T> query() {
+        return new QueryWrapper<>();
+    }
+
+    /**
+     * 获取UpdateWrapper
+     *
+     * @param <T>
+     * @return
+     */
+    public static <T> UpdateWrapper<T> update() {
+        return new UpdateWrapper<>();
+    }
+
+    /**
+     * 获取LambdaQueryWrapper
+     *
+     * @param entity
+     * @param <T>
+     * @return
+     */
+    public static <T> LambdaQueryWrapper<T> query(T entity) {
+        return new LambdaQueryWrapper(entity);
+    }
+
+    /**
+     * 获取LambdaUpdateWrapper
+     *
+     * @param entity
+     * @param <T>
+     * @return
+     */
+    public static <T> LambdaUpdateWrapper<T> update(T entity) {
+        return new UpdateWrapper<>(entity).lambda();
+    }
+
+    /**
+     * 获取EmptyWrapper
+     *
+     * @param <T>
+     * @return
+     */
+    public static <T> QueryWrapper<T> emptyQueryWrapper() {
+        return (QueryWrapper<T>) emptyWrapper;
+    }
+}