Просмотр исходного кода

新增 adapter 2.x 到 3.x 的适配包 3.1 后将删除该包

hubin 7 лет назад
Родитель
Сommit
88e5bb0d95

+ 9 - 0
mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/BaseMapper.java

@@ -0,0 +1,9 @@
+package com.baomidou.mybatisplus.mapper;
+
+/**
+ * 请尽快修改该类的引用 mp 3.1 将删除该类
+ */
+@Deprecated
+public interface BaseMapper extends com.baomidou.mybatisplus.core.mapper.BaseMapper {
+
+}

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

@@ -0,0 +1,47 @@
+package com.baomidou.mybatisplus.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.EntityWrapper;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+
+/**
+ * 请尽快修改该类的引用 mp 3.1 将删除该类
+ */
+@Deprecated
+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);
+    }
+
+}

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

@@ -0,0 +1,147 @@
+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;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
+
+/**
+ * 请尽快修改该类的引用 mp 3.1 将删除该类
+ */
+@Deprecated
+@SuppressWarnings("serial")
+public class EntityWrapper<T> extends Wrapper<T> {
+
+    /**
+     * 数据库表映射实体类
+     */
+    protected T entity = null;
+    /**
+     * SQL 查询字段内容,例如:id,name,age
+     */
+    protected String sqlSelect = null;
+
+    public EntityWrapper() {
+        /* 注意,传入查询参数 */
+    }
+
+    public EntityWrapper(T entity) {
+        this.entity = entity;
+    }
+
+    public EntityWrapper(T entity, String sqlSelect) {
+        this.entity = entity;
+        this.sqlSelect = sqlSelect;
+    }
+
+    @Override
+    public T getEntity() {
+        return entity;
+    }
+
+    public void setEntity(T entity) {
+        this.entity = entity;
+    }
+
+    public String getSqlSelect() {
+        return StringUtils.isEmpty(sqlSelect) ? null : SqlUtils.stripSqlInjection(sqlSelect);
+    }
+
+    public Wrapper<T> setSqlSelect(String sqlSelect) {
+        if (StringUtils.isNotEmpty(sqlSelect)) {
+            this.sqlSelect = sqlSelect;
+        }
+        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);
+    }
+
+}

+ 9 - 0
mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/MetaObjectHandler.java

@@ -0,0 +1,9 @@
+package com.baomidou.mybatisplus.mapper;
+
+/**
+ * 请尽快修改该类的引用 mp 3.1 将删除该类
+ */
+@Deprecated
+public abstract class MetaObjectHandler extends com.baomidou.mybatisplus.core.handlers.MetaObjectHandler {
+
+}

+ 9 - 0
mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/SqlCondition.java

@@ -0,0 +1,9 @@
+package com.baomidou.mybatisplus.mapper;
+
+/**
+ * 请尽快修改该类的引用 mp 3.1 将删除该类
+ */
+@Deprecated
+public class SqlCondition extends com.baomidou.mybatisplus.annotation.SqlCondition {
+
+}

+ 9 - 0
mybatis-plus-adapter/src/main/java/com/baomidou/mybatisplus/mapper/SqlRunner.java

@@ -0,0 +1,9 @@
+package com.baomidou.mybatisplus.mapper;
+
+/**
+ * 请尽快该类 mp 3.1 将删除该类
+ */
+@Deprecated
+public class SqlRunner extends com.baomidou.mybatisplus.extension.toolkit.SqlRunner {
+
+}

+ 1 - 1
settings.gradle

@@ -4,5 +4,5 @@ include 'mybatis-plus-core'
 include 'mybatis-plus-annotation'
 include 'mybatis-plus-extension'
 include 'mybatis-plus-generator'
-
+include 'mybatis-plus-adapter'