Bläddra i källkod

发布 3.0.1-SNAPSHOT

hubin 7 år sedan
förälder
incheckning
e8ea938af9
27 ändrade filer med 777 tillägg och 127 borttagningar
  1. 1 1
      build.gradle
  2. 6 6
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java
  3. 4 4
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/enums/SqlMethod.java
  4. 20 4
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/DefaultSqlInjector.java
  5. 4 6
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/SelectBatchByIds.java
  6. 3 3
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/UpdateById.java
  7. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java
  8. 172 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/LogicAbstractMethod.java
  9. 24 25
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/LogicSqlInjector.java
  10. 3 2
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDelete.java
  11. 3 2
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDeleteBatchByIds.java
  12. 3 2
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDeleteById.java
  13. 3 2
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDeleteByMap.java
  14. 0 64
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicMethod.java
  15. 44 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectBatchByIds.java
  16. 43 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectById.java
  17. 45 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectByMap.java
  18. 42 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectCount.java
  19. 43 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectList.java
  20. 45 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectMaps.java
  21. 45 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectMapsPage.java
  22. 43 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectObjs.java
  23. 43 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectOne.java
  24. 43 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectPage.java
  25. 43 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicUpdate.java
  26. 47 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicUpdateById.java
  27. 4 5
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java

+ 1 - 1
build.gradle

@@ -56,7 +56,7 @@ ext {
 
 allprojects {
     group = 'com.baomidou'
-    version = '3.0.1-Alpha'
+    version = '3.0.1-SNAPSHOT'
 }
 
 description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"

+ 6 - 6
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java

@@ -48,10 +48,10 @@ public class MybatisConfiguration extends Configuration {
      * 初始化调用
      */
     public MybatisConfiguration() {
-        this.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
+        setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
         System.out.println("  _ _     /_ _ _/_. ____  /    _");
         System.out.println(" / / //_//_//_|/ /_\\  /_///_/_\\ ");
-        System.out.println("      _/             /             init success.");
+        System.out.println("      _/             /             V.3");
     }
 
     /**
@@ -66,18 +66,18 @@ public class MybatisConfiguration extends Configuration {
      */
     @Override
     public void addMappedStatement(MappedStatement ms) {
-        logger.debug("addMappedStatement: " + ms.getId());
+        MybatisConfiguration.logger.debug("addMappedStatement: " + ms.getId());
         if (GlobalConfigUtils.isRefresh(ms.getConfiguration())) {
             /*
              * 支持是否自动刷新 XML 变更内容,开发环境使用【 注:生产环境勿用!】
              */
-            this.mappedStatements.remove(ms.getId());
+            mappedStatements.remove(ms.getId());
         } else {
-            if (this.mappedStatements.containsKey(ms.getId())) {
+            if (mappedStatements.containsKey(ms.getId())) {
                 /*
                  * 说明已加载了xml中的节点; 忽略mapper中的SqlProvider数据
                  */
-                logger.error("mapper[" + ms.getId() + "] is ignored, because it's exists, maybe from xml file");
+                MybatisConfiguration.logger.error("mapper[" + ms.getId() + "] is ignored, because it's exists, maybe from xml file");
                 return;
             }
         }

+ 4 - 4
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/enums/SqlMethod.java

@@ -82,22 +82,22 @@ public enum SqlMethod {
     private final String desc;
     private final String sql;
 
-    SqlMethod(final String method, final String desc, final String sql) {
+    SqlMethod(String method, String desc, String sql) {
         this.method = method;
         this.desc = desc;
         this.sql = sql;
     }
 
     public String getMethod() {
-        return this.method;
+        return method;
     }
 
     public String getDesc() {
-        return this.desc;
+        return desc;
     }
 
     public String getSql() {
-        return this.sql;
+        return sql;
     }
 
 }

+ 20 - 4
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/DefaultSqlInjector.java

@@ -15,13 +15,30 @@
  */
 package com.baomidou.mybatisplus.core.injector;
 
-import com.baomidou.mybatisplus.core.injector.methods.*;
-import org.apache.ibatis.session.Configuration;
-
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import org.apache.ibatis.session.Configuration;
+
+import com.baomidou.mybatisplus.core.injector.methods.Delete;
+import com.baomidou.mybatisplus.core.injector.methods.DeleteBatchByIds;
+import com.baomidou.mybatisplus.core.injector.methods.DeleteById;
+import com.baomidou.mybatisplus.core.injector.methods.DeleteByMap;
+import com.baomidou.mybatisplus.core.injector.methods.Insert;
+import com.baomidou.mybatisplus.core.injector.methods.SelectBatchByIds;
+import com.baomidou.mybatisplus.core.injector.methods.SelectById;
+import com.baomidou.mybatisplus.core.injector.methods.SelectByMap;
+import com.baomidou.mybatisplus.core.injector.methods.SelectCount;
+import com.baomidou.mybatisplus.core.injector.methods.SelectList;
+import com.baomidou.mybatisplus.core.injector.methods.SelectMaps;
+import com.baomidou.mybatisplus.core.injector.methods.SelectMapsPage;
+import com.baomidou.mybatisplus.core.injector.methods.SelectObjs;
+import com.baomidou.mybatisplus.core.injector.methods.SelectOne;
+import com.baomidou.mybatisplus.core.injector.methods.SelectPage;
+import com.baomidou.mybatisplus.core.injector.methods.Update;
+import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
+
 
 /**
  * <p>
@@ -53,7 +70,6 @@ public class DefaultSqlInjector extends AbstractSqlInjector {
             new SelectMapsPage(),
             new SelectObjs(),
             new SelectList(),
-            new SelectList(),
             new SelectPage()
         ).collect(Collectors.toList());
     }

+ 4 - 6
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/SelectBatchByIds.java

@@ -35,12 +35,10 @@ public class SelectBatchByIds extends AbstractMethod {
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
         SqlMethod sqlMethod = SqlMethod.SELECT_BATCH_BY_IDS;
-        StringBuilder ids = new StringBuilder();
-        ids.append("<foreach item=\"item\" index=\"index\" collection=\"coll\" separator=\",\">");
-        ids.append("#{item}");
-        ids.append("</foreach>");
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(),
-            this.sqlSelectColumns(tableInfo, false), tableInfo.getTableName(), tableInfo.getKeyColumn(), ids.toString()), modelClass);
-        return this.addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+            sqlSelectColumns(tableInfo, false), tableInfo.getTableName(), tableInfo.getKeyColumn(),
+            new StringBuilder("<foreach item=\"item\" collection=\"coll\" separator=\",\">#{item}</foreach>").toString()),
+            modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
     }
 }

+ 3 - 3
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/UpdateById.java

@@ -35,13 +35,13 @@ public class UpdateById extends AbstractMethod {
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
         SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
-        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), this.sqlSet(true, false, tableInfo, "et."),
+        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet(true, false, tableInfo, "et."),
             tableInfo.getKeyColumn(), new StringBuilder("et.").append(tableInfo.getKeyProperty()).toString(),
             new StringBuilder("<if test=\"et instanceof java.util.Map\">")
                 .append("<if test=\"et.MP_OPTLOCK_VERSION_ORIGINAL!=null\">")
-                .append("  AND ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}")
+                .append(" AND ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}")
                 .append("</if></if>"));
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-        return this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+        return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
     }
 }

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java

@@ -240,6 +240,6 @@ public interface BaseMapper<T> {
      * @param page         分页查询条件
      * @param queryWrapper 实体对象封装操作类
      */
-    List<Map<String, Object>> selectMapsPage(IPage page, @Param("ew") Wrapper<T> queryWrapper);
+    IPage<Map<String, Object>> selectMapsPage(IPage<T> page, @Param("ew") Wrapper<T> queryWrapper);
 
 }

+ 172 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/LogicAbstractMethod.java

@@ -0,0 +1,172 @@
+/*
+ * 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 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.extension.injector;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+
+/**
+ * <p>
+ * 抽象的注入方法类
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public abstract class LogicAbstractMethod extends AbstractMethod {
+
+    /**
+     * <p>
+     * SQL 更新 set 语句
+     * </p>
+     *
+     * @param table 表信息
+     * @return sql and 片段
+     */
+    public String getLogicDeleteSql(TableInfo table) {
+        StringBuilder sql = new StringBuilder();
+        List<TableFieldInfo> fieldList = table.getFieldList();
+        for (TableFieldInfo fieldInfo : fieldList) {
+            if (fieldInfo.isLogicDelete()) {
+                sql.append(" AND ").append(fieldInfo.getColumn());
+                if (StringUtils.isCharSequence(fieldInfo.getPropertyType())) {
+                    sql.append("='").append(fieldInfo.getLogicNotDeleteValue()).append("'");
+                } else {
+                    sql.append("=").append(fieldInfo.getLogicNotDeleteValue());
+                }
+            }
+        }
+        return sql.toString();
+    }
+
+    /**
+     * <p>
+     * SQL 更新 set 语句
+     * </p>
+     *
+     * @param table 表信息
+     * @return sql set 片段
+     */
+    protected String sqlLogicSet(TableInfo table) {
+        List<TableFieldInfo> fieldList = table.getFieldList();
+        StringBuilder set = new StringBuilder("SET ");
+        int i = 0;
+        for (TableFieldInfo fieldInfo : fieldList) {
+            if (fieldInfo.isLogicDelete()) {
+                if (++i > 1) {
+                    set.append(",");
+                }
+                set.append(fieldInfo.getColumn()).append("=");
+                if (StringUtils.isCharSequence(fieldInfo.getPropertyType())) {
+                    set.append("'").append(fieldInfo.getLogicDeleteValue()).append("'");
+                } else {
+                    set.append(fieldInfo.getLogicDeleteValue());
+                }
+            }
+        }
+        return set.toString();
+    }
+
+    // ------------ 处理逻辑删除条件过滤 ------------
+
+    @Override
+    protected String sqlWhere(TableInfo table) {
+        if (table.isLogicDelete()) {
+            StringBuilder where = new StringBuilder("<where>");
+            // 过滤逻辑
+            List<TableFieldInfo> fieldList = table.getFieldList();
+            // EW 逻辑
+            if (StringUtils.isNotEmpty(table.getKeyProperty())) {
+                where.append("<if test=\"ew.").append(table.getKeyProperty()).append("!=null\">");
+                where.append(" AND ").append(table.getKeyColumn()).append("=#{ew.");
+                where.append(table.getKeyProperty()).append("}");
+                where.append("</if>");
+            }
+            for (TableFieldInfo fieldInfo : fieldList) {
+                where.append(convertIfTag(fieldInfo, "ew.", false));
+                where.append(" AND ").append(sqlCondition(fieldInfo.getCondition(),
+                    fieldInfo.getColumn(), "ew." + fieldInfo.getEl()));
+                where.append(convertIfTag(fieldInfo, true));
+            }
+            // 过滤逻辑
+            where.append(getLogicDeleteSql(table));
+            where.append("</where>");
+            return where.toString();
+        }
+        // 正常逻辑
+        return super.sqlWhere(table);
+    }
+
+    @Override
+    protected String sqlWhereEntityWrapper(TableInfo table) {
+        if (table.isLogicDelete()) {
+            StringBuilder where = new StringBuilder(128);
+            where.append("<where>");
+            where.append("<choose><when test=\"ew!=null\">");
+            where.append("<if test=\"ew.entity!=null\">");
+            if (StringUtils.isNotEmpty(table.getKeyProperty())) {
+                where.append("<if test=\"ew.entity.").append(table.getKeyProperty()).append("!=null\">");
+                where.append(" AND ").append(table.getKeyColumn()).append("=#{ew.entity.");
+                where.append(table.getKeyProperty()).append("}");
+                where.append("</if>");
+            }
+            List<TableFieldInfo> fieldList = table.getFieldList();
+            for (TableFieldInfo fieldInfo : fieldList) {
+                where.append(convertIfTag(fieldInfo, "ew.entity.", false));
+                where.append(" AND ").append(sqlCondition(fieldInfo.getCondition(),
+                    fieldInfo.getColumn(), "ew.entity." + fieldInfo.getEl()));
+                where.append(convertIfTag(fieldInfo, true));
+            }
+            where.append("</if>");
+            where.append(getLogicDeleteSql(table));
+            where.append("<if test=\"ew.sqlSegment!=null\">${ew.sqlSegment}</if>");
+            where.append("</when><otherwise>");
+            where.append(getLogicDeleteSql(table));
+            where.append("</otherwise></choose>");
+            where.append("</where>");
+            return where.toString();
+        }
+        // 正常逻辑
+        return super.sqlWhereEntityWrapper(table);
+    }
+
+    @Override
+    protected String sqlWhereByMap(TableInfo table) {
+        if (table.isLogicDelete()) {
+            StringBuilder where = new StringBuilder();
+            where.append("<where>");
+            // MAP 逻辑
+            where.append("<if test=\"cm!=null and !cm.isEmpty\">");
+            where.append("<foreach collection=\"cm.keys\" item=\"k\" separator=\"AND\">");
+            where.append("<if test=\"cm[k] != null\">");
+            where.append("${k} = #{cm[${k}]}");
+            where.append("</if>");
+            where.append("</foreach>");
+            where.append("</if>");
+            // 过滤逻辑
+            where.append(getLogicDeleteSql(table));
+            where.append("</where>");
+            return where.toString();
+        }
+        // 正常逻辑
+        return super.sqlWhereByMap(table);
+    }
+
+}

+ 24 - 25
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/LogicSqlInjector.java

@@ -29,18 +29,18 @@ import com.baomidou.mybatisplus.extension.injector.methods.LogicDelete;
 import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteBatchByIds;
 import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteById;
 import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByMap;
-import com.baomidou.mybatisplus.core.injector.methods.SelectBatchByIds;
-import com.baomidou.mybatisplus.core.injector.methods.SelectById;
-import com.baomidou.mybatisplus.core.injector.methods.SelectByMap;
-import com.baomidou.mybatisplus.core.injector.methods.SelectCount;
-import com.baomidou.mybatisplus.core.injector.methods.SelectList;
-import com.baomidou.mybatisplus.core.injector.methods.SelectMaps;
-import com.baomidou.mybatisplus.core.injector.methods.SelectMapsPage;
-import com.baomidou.mybatisplus.core.injector.methods.SelectObjs;
-import com.baomidou.mybatisplus.core.injector.methods.SelectOne;
-import com.baomidou.mybatisplus.core.injector.methods.SelectPage;
-import com.baomidou.mybatisplus.core.injector.methods.Update;
-import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectBatchByIds;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectById;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectByMap;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectCount;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectList;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectMaps;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectMapsPage;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectObjs;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectOne;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicSelectPage;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicUpdate;
+import com.baomidou.mybatisplus.extension.injector.methods.LogicUpdateById;
 
 
 /**
@@ -62,19 +62,18 @@ public class LogicSqlInjector extends AbstractSqlInjector {
             new LogicDeleteByMap(),
             new LogicDeleteById(),
             new LogicDeleteBatchByIds(),
-            new Update(),
-            new UpdateById(),
-            new SelectById(),
-            new SelectBatchByIds(),
-            new SelectByMap(),
-            new SelectOne(),
-            new SelectCount(),
-            new SelectMaps(),
-            new SelectMapsPage(),
-            new SelectObjs(),
-            new SelectList(),
-            new SelectList(),
-            new SelectPage()
+            new LogicUpdate(),
+            new LogicUpdateById(),
+            new LogicSelectById(),
+            new LogicSelectBatchByIds(),
+            new LogicSelectByMap(),
+            new LogicSelectOne(),
+            new LogicSelectCount(),
+            new LogicSelectMaps(),
+            new LogicSelectMapsPage(),
+            new LogicSelectObjs(),
+            new LogicSelectList(),
+            new LogicSelectPage()
         ).collect(Collectors.toList());
     }
 

+ 3 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDelete.java

@@ -20,6 +20,7 @@ import org.apache.ibatis.mapping.SqlSource;
 
 import com.baomidou.mybatisplus.core.enums.SqlMethod;
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
 
 /**
  * <p>
@@ -27,9 +28,9 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
  * </p>
  *
  * @author hubin
- * @since 2018-04-06
+ * @since 2018-06-13
  */
-public class LogicDelete extends LogicMethod {
+public class LogicDelete extends LogicAbstractMethod {
 
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

+ 3 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDeleteBatchByIds.java

@@ -20,6 +20,7 @@ import org.apache.ibatis.mapping.SqlSource;
 
 import com.baomidou.mybatisplus.core.enums.SqlMethod;
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
 
 /**
  * <p>
@@ -27,9 +28,9 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
  * </p>
  *
  * @author hubin
- * @since 2018-04-06
+ * @since 2018-06-13
  */
-public class LogicDeleteBatchByIds extends LogicMethod {
+public class LogicDeleteBatchByIds extends LogicAbstractMethod {
 
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

+ 3 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDeleteById.java

@@ -20,6 +20,7 @@ import org.apache.ibatis.mapping.SqlSource;
 
 import com.baomidou.mybatisplus.core.enums.SqlMethod;
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
 
 /**
  * <p>
@@ -27,9 +28,9 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
  * </p>
  *
  * @author hubin
- * @since 2018-04-06
+ * @since 2018-06-13
  */
-public class LogicDeleteById extends LogicMethod {
+public class LogicDeleteById extends LogicAbstractMethod {
 
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

+ 3 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicDeleteByMap.java

@@ -22,6 +22,7 @@ import org.apache.ibatis.mapping.SqlSource;
 
 import com.baomidou.mybatisplus.core.enums.SqlMethod;
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
 
 /**
  * <p>
@@ -29,9 +30,9 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
  * </p>
  *
  * @author hubin
- * @since 2018-04-06
+ * @since 2018-06-13
  */
-public class LogicDeleteByMap extends LogicMethod {
+public class LogicDeleteByMap extends LogicAbstractMethod {
 
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

+ 0 - 64
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicMethod.java

@@ -1,64 +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 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.extension.injector.methods;
-
-import java.util.List;
-
-import com.baomidou.mybatisplus.core.injector.AbstractMethod;
-import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
-import com.baomidou.mybatisplus.core.metadata.TableInfo;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-
-/**
- * <p>
- * 抽象的注入方法类
- * </p>
- *
- * @author hubin
- * @since 2018-04-06
- */
-public abstract class LogicMethod extends AbstractMethod {
-
-
-    /**
-     * <p>
-     * SQL 更新 set 语句
-     * </p>
-     *
-     * @param table 表信息
-     * @return sql set 片段
-     */
-    protected String sqlLogicSet(TableInfo table) {
-        List<TableFieldInfo> fieldList = table.getFieldList();
-        StringBuilder set = new StringBuilder("SET ");
-        int i = 0;
-        for (TableFieldInfo fieldInfo : fieldList) {
-            if (fieldInfo.isLogicDelete()) {
-                if (++i > 1) {
-                    set.append(",");
-                }
-                set.append(fieldInfo.getColumn()).append("=");
-                if (StringUtils.isCharSequence(fieldInfo.getPropertyType())) {
-                    set.append("'").append(fieldInfo.getLogicDeleteValue()).append("'");
-                } else {
-                    set.append(fieldInfo.getLogicDeleteValue());
-                }
-            }
-        }
-        return set.toString();
-    }
-
-}

+ 44 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectBatchByIds.java

@@ -0,0 +1,44 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectBatchByIds extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.LOGIC_SELECT_BATCH_BY_IDS;
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(),
+            sqlSelectColumns(tableInfo, false), tableInfo.getTableName(), tableInfo.getKeyColumn(),
+            new StringBuilder("<foreach item=\"item\" collection=\"coll\" separator=\",\">#{item}</foreach>").toString(),
+            getLogicDeleteSql(tableInfo)), modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+    }
+}

+ 43 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectById.java

@@ -0,0 +1,43 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+import org.apache.ibatis.scripting.defaults.RawSqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectById extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.LOGIC_SELECT_BY_ID;
+        SqlSource sqlSource = new RawSqlSource(configuration, String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, false),
+            tableInfo.getTableName(), tableInfo.getKeyColumn(), tableInfo.getKeyProperty(), getLogicDeleteSql(tableInfo)), Object.class);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+    }
+}

+ 45 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectByMap.java

@@ -0,0 +1,45 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import java.util.Map;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectByMap extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_BY_MAP;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, false),
+            tableInfo.getTableName(), sqlWhereByMap(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Map.class);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+    }
+}

+ 42 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectCount.java

@@ -0,0 +1,42 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectCount extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_COUNT;
+        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlWhereEntityWrapper(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, Integer.class, null);
+    }
+}

+ 43 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectList.java

@@ -0,0 +1,43 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectList extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_LIST;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+    }
+}

+ 45 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectMaps.java

@@ -0,0 +1,45 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import java.util.Map;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectMaps extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_MAPS;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, Map.class, tableInfo);
+    }
+}

+ 45 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectMapsPage.java

@@ -0,0 +1,45 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import java.util.Map;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectMapsPage extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_MAPS_PAGE;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, Map.class, tableInfo);
+    }
+}

+ 43 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectObjs.java

@@ -0,0 +1,43 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectObjs extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_OBJS;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+    }
+}

+ 43 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectOne.java

@@ -0,0 +1,43 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectOne extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_ONE;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, false),
+            tableInfo.getTableName(), sqlWhere(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+    }
+}

+ 43 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicSelectPage.java

@@ -0,0 +1,43 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-13
+ */
+public class LogicSelectPage extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_PAGE;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
+    }
+}

+ 43 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicUpdate.java

@@ -0,0 +1,43 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 删除
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class LogicUpdate extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.UPDATE;
+        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet(true, true, tableInfo, "et."),
+            sqlWhereEntityWrapper(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+    }
+}

+ 47 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/LogicUpdateById.java

@@ -0,0 +1,47 @@
+/*
+ * 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 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.extension.injector.methods;
+
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
+
+/**
+ * <p>
+ * 根据 ID 更新有值字段
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class LogicUpdateById extends LogicAbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
+        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet(true, false, tableInfo, "et."),
+            tableInfo.getKeyColumn(), new StringBuilder("et.").append(tableInfo.getKeyProperty()).toString(),
+            new StringBuilder("<if test=\"et instanceof java.util.Map\">")
+                .append("<if test=\"et.MP_OPTLOCK_VERSION_ORIGINAL!=null\">")
+                .append(" AND ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}")
+                .append("</if></if>").append(getLogicDeleteSql(tableInfo)));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+    }
+}

+ 4 - 5
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java

@@ -67,7 +67,6 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
         return SqlHelper.retBool(result);
     }
 
-    @SuppressWarnings("unchecked")
     protected Class<T> currentModelClass() {
         return ReflectionKit.getSuperClassGenricType(getClass(), 1);
     }
@@ -94,7 +93,7 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
     @Transactional(rollbackFor = Exception.class)
     @Override
     public boolean insert(T entity) {
-        return retBool(baseMapper.insert(entity));
+        return ServiceImpl.retBool(baseMapper.insert(entity));
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -236,13 +235,13 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
     @Transactional(rollbackFor = Exception.class)
     @Override
     public boolean updateById(T entity) {
-        return retBool(baseMapper.updateById(entity));
+        return ServiceImpl.retBool(baseMapper.updateById(entity));
     }
 
     @Transactional(rollbackFor = Exception.class)
     @Override
     public boolean update(T entity, Wrapper<T> wrapper) {
-        return retBool(baseMapper.update(entity, wrapper));
+        return ServiceImpl.retBool(baseMapper.update(entity, wrapper));
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -335,7 +334,7 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
     @Override
     public IPage<Map<String, Object>> selectMapsPage(IPage page, Wrapper<T> wrapper) {
         wrapper = (Wrapper<T>) SqlHelper.fillWrapper(page, wrapper);
-        return page.setRecords(baseMapper.selectMapsPage(page, wrapper));
+        return baseMapper.selectMapsPage(page, wrapper);
     }
 
     @Override