Browse Source

目录调整

nieqiurong 8 years ago
parent
commit
635fbab01f
100 changed files with 2356 additions and 2360 deletions
  1. 17 4
      .gitignore
  2. 0 0
      build.gradle
  3. 0 17
      mybatis-plus/.gitignore
  4. 0 0
      pom.xml
  5. 0 0
      settings.gradle
  6. 0 0
      src/main/java/com/baomidou/mybatisplus/MybatisAbstractSQL.java
  7. 0 0
      src/main/java/com/baomidou/mybatisplus/MybatisConfiguration.java
  8. 268 268
      src/main/java/com/baomidou/mybatisplus/MybatisDefaultParameterHandler.java
  9. 0 0
      src/main/java/com/baomidou/mybatisplus/MybatisMapperAnnotationBuilder.java
  10. 0 0
      src/main/java/com/baomidou/mybatisplus/MybatisMapperRegistry.java
  11. 75 75
      src/main/java/com/baomidou/mybatisplus/MybatisSessionFactoryBuilder.java
  12. 0 0
      src/main/java/com/baomidou/mybatisplus/MybatisSqlSessionTemplate.java
  13. 438 438
      src/main/java/com/baomidou/mybatisplus/MybatisXMLConfigBuilder.java
  14. 39 39
      src/main/java/com/baomidou/mybatisplus/MybatisXMLLanguageDriver.java
  15. 0 0
      src/main/java/com/baomidou/mybatisplus/MybatisXMLMapperBuilder.java
  16. 398 398
      src/main/java/com/baomidou/mybatisplus/activerecord/Model.java
  17. 0 0
      src/main/java/com/baomidou/mybatisplus/activerecord/package-info.java
  18. 52 52
      src/main/java/com/baomidou/mybatisplus/annotations/KeySequence.java
  19. 0 0
      src/main/java/com/baomidou/mybatisplus/annotations/TableField.java
  20. 52 52
      src/main/java/com/baomidou/mybatisplus/annotations/TableId.java
  21. 0 0
      src/main/java/com/baomidou/mybatisplus/annotations/TableLogic.java
  22. 49 49
      src/main/java/com/baomidou/mybatisplus/annotations/TableName.java
  23. 0 0
      src/main/java/com/baomidou/mybatisplus/annotations/Version.java
  24. 4 4
      src/main/java/com/baomidou/mybatisplus/annotations/package-info.java
  25. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/Column.java
  26. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/CountOptimize.java
  27. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/DefaultMetaObjectHandler.java
  28. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/GlobalConfiguration.java
  29. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/OracleKeyGenerator.java
  30. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/TableFieldInfo.java
  31. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/TableInfo.java
  32. 0 0
      src/main/java/com/baomidou/mybatisplus/entity/package-info.java
  33. 0 0
      src/main/java/com/baomidou/mybatisplus/enums/DBType.java
  34. 0 0
      src/main/java/com/baomidou/mybatisplus/enums/FieldStrategy.java
  35. 0 0
      src/main/java/com/baomidou/mybatisplus/enums/IdType.java
  36. 0 0
      src/main/java/com/baomidou/mybatisplus/enums/Optimize.java
  37. 0 0
      src/main/java/com/baomidou/mybatisplus/enums/SqlLike.java
  38. 0 0
      src/main/java/com/baomidou/mybatisplus/enums/SqlMethod.java
  39. 0 0
      src/main/java/com/baomidou/mybatisplus/enums/package-info.java
  40. 0 0
      src/main/java/com/baomidou/mybatisplus/exceptions/MybatisPlusException.java
  41. 0 0
      src/main/java/com/baomidou/mybatisplus/exceptions/package-info.java
  42. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/AbstractGenerator.java
  43. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java
  44. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/InjectionConfig.java
  45. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/ConstVal.java
  46. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java
  47. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/FileOutConfig.java
  48. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/GlobalConfig.java
  49. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/ITypeConvert.java
  50. 138 138
      src/main/java/com/baomidou/mybatisplus/generator/config/PackageConfig.java
  51. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java
  52. 88 88
      src/main/java/com/baomidou/mybatisplus/generator/config/TemplateConfig.java
  53. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java
  54. 4 4
      src/main/java/com/baomidou/mybatisplus/generator/config/builder/package-info.java
  55. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/converts/MySqlTypeConvert.java
  56. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/converts/OracleTypeConvert.java
  57. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/converts/PostgreSqlTypeConvert.java
  58. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/converts/SqlServerTypeConvert.java
  59. 4 4
      src/main/java/com/baomidou/mybatisplus/generator/config/package-info.java
  60. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/po/TableField.java
  61. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java
  62. 4 4
      src/main/java/com/baomidou/mybatisplus/generator/config/po/package-info.java
  63. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/rules/DbColumnType.java
  64. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/rules/DbType.java
  65. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategy.java
  66. 0 0
      src/main/java/com/baomidou/mybatisplus/generator/config/rules/QuerySQL.java
  67. 4 4
      src/main/java/com/baomidou/mybatisplus/generator/config/rules/package-info.java
  68. 4 4
      src/main/java/com/baomidou/mybatisplus/generator/package-info.java
  69. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java
  70. 253 253
      src/main/java/com/baomidou/mybatisplus/mapper/BaseMapper.java
  71. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/Condition.java
  72. 82 82
      src/main/java/com/baomidou/mybatisplus/mapper/EntityWrapper.java
  73. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/IKeyGenerator.java
  74. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/ISqlInjector.java
  75. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/LogicSqlInjector.java
  76. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/MetaObjectHandler.java
  77. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/SqlHelper.java
  78. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/SqlPlus.java
  79. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/SqlRunner.java
  80. 0 0
      src/main/java/com/baomidou/mybatisplus/mapper/Wrapper.java
  81. 4 4
      src/main/java/com/baomidou/mybatisplus/mapper/package-info.java
  82. 4 4
      src/main/java/com/baomidou/mybatisplus/package-info.java
  83. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/CachePaginationInterceptor.java
  84. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/OptimisticLockerInterceptor.java
  85. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/Page.java
  86. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/PaginationInterceptor.java
  87. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/PerformanceInterceptor.java
  88. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/SqlExplainInterceptor.java
  89. 4 4
      src/main/java/com/baomidou/mybatisplus/plugins/package-info.java
  90. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/DialectFactory.java
  91. 40 40
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/IDialect.java
  92. 217 217
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/Pagination.java
  93. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/DB2Dialect.java
  94. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/H2Dialect.java
  95. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/HSQLDialect.java
  96. 37 37
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/MySqlDialect.java
  97. 39 39
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/OracleDialect.java
  98. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/PostgreDialect.java
  99. 0 0
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/SQLServer2005Dialect.java
  100. 38 38
      src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/SQLServerDialect.java

+ 17 - 4
.gitignore

@@ -1,5 +1,18 @@
+/target/
+/.settings/
+/.project
+/.classpath
+
+# IntelliJ project files
+.idea
+*.iml
+out
+html
+
+# gradle
+.gradle
+build
+
+# MacOS
 .DS_Store
 .DS_Store
-D:
-/mybatis-plus/gradlew
-/mybatis-plus/*.bat
-/mybatis-plus/gradle/wrapper
+/.gradle

+ 0 - 0
mybatis-plus/build.gradle → build.gradle


+ 0 - 17
mybatis-plus/.gitignore

@@ -1,17 +0,0 @@
-/target/
-/.settings/
-/.project
-/.classpath
-
-# IntelliJ project files
-.idea
-*.iml
-out
-html
-
-# gradle
-.gradle
-build
-
-# MacOS
-.DS_Store

+ 0 - 0
mybatis-plus/pom.xml → pom.xml


+ 0 - 0
mybatis-plus/settings.gradle → settings.gradle


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisAbstractSQL.java → src/main/java/com/baomidou/mybatisplus/MybatisAbstractSQL.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisConfiguration.java → src/main/java/com/baomidou/mybatisplus/MybatisConfiguration.java


+ 268 - 268
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisDefaultParameterHandler.java → src/main/java/com/baomidou/mybatisplus/MybatisDefaultParameterHandler.java

@@ -1,268 +1,268 @@
-/**
- * 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;
-
-import java.lang.reflect.Field;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.ibatis.executor.ErrorContext;
-import org.apache.ibatis.mapping.BoundSql;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.mapping.ParameterMapping;
-import org.apache.ibatis.mapping.ParameterMode;
-import org.apache.ibatis.mapping.SqlCommandType;
-import org.apache.ibatis.reflection.MetaObject;
-import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.type.JdbcType;
-import org.apache.ibatis.type.TypeException;
-import org.apache.ibatis.type.TypeHandler;
-import org.apache.ibatis.type.TypeHandlerRegistry;
-
-import com.baomidou.mybatisplus.entity.GlobalConfiguration;
-import com.baomidou.mybatisplus.entity.TableInfo;
-import com.baomidou.mybatisplus.enums.IdType;
-import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
-import com.baomidou.mybatisplus.toolkit.IdWorker;
-import com.baomidou.mybatisplus.toolkit.MapUtils;
-import com.baomidou.mybatisplus.toolkit.StringUtils;
-import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
-
-/**
- * <p>
- * 自定义 ParameterHandler 重装构造函数,填充插入方法主键 ID
- * </p>
- *
- * @author hubin
- * @Date 2016-03-11
- */
-public class MybatisDefaultParameterHandler extends DefaultParameterHandler {
-
-    /**
-     * @see org.apache.ibatis.mapping.BoundSql
-     */
-    private static final Field additionalParametersField = getAdditionalParametersField();
-    private final TypeHandlerRegistry typeHandlerRegistry;
-    private final MappedStatement mappedStatement;
-    private final Object parameterObject;
-    private BoundSql boundSql;
-    private Configuration configuration;
-    public MybatisDefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
-        super(mappedStatement, processBatch(mappedStatement, parameterObject), boundSql);
-        this.mappedStatement = mappedStatement;
-        this.configuration = mappedStatement.getConfiguration();
-        this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
-        this.parameterObject = parameterObject;
-        this.boundSql = boundSql;
-    }
-
-    /**
-     * 反射获取BoundSql中additionalParameters参数字段
-     *
-     * @return
-     * @see org.apache.ibatis.mapping.BoundSql
-     */
-    private static Field getAdditionalParametersField() {
-        try {
-            Field additionalParametersField = BoundSql.class.getDeclaredField("additionalParameters");
-            additionalParametersField.setAccessible(true);
-            return additionalParametersField;
-        } catch (NoSuchFieldException e) {
-            // ignored, Because it will never happen.
-        }
-        return null;
-    }
-
-    /**
-     * <p>
-     * 批量(填充主键 ID)
-     * </p>
-     *
-     * @param ms
-     * @param parameterObject 插入数据库对象
-     * @return
-     */
-    protected static Object processBatch(MappedStatement ms, Object parameterObject) {
-        boolean isFill = false;
-        // 全局配置是否配置填充器
-        MetaObjectHandler metaObjectHandler = GlobalConfiguration.getMetaObjectHandler(ms.getConfiguration());
-        /* 只处理插入或更新操作 */
-        if (ms.getSqlCommandType() == SqlCommandType.INSERT) {
-            isFill = true;
-        } else if (ms.getSqlCommandType() == SqlCommandType.UPDATE
-                && metaObjectHandler.openUpdateFill()) {
-            isFill = true;
-        }
-        if (isFill) {
-            Collection<Object> parameters = getParameters(parameterObject);
-            if (null != parameters) {
-                List<Object> objList = new ArrayList<>();
-                for (Object parameter : parameters) {
-                    TableInfo tableInfo = TableInfoHelper.getTableInfo(parameter.getClass());
-                    if (null != tableInfo) {
-                        objList.add(populateKeys(metaObjectHandler, tableInfo, ms, parameter));
-                    } else {
-                        /*
-                         * 非表映射类不处理
-						 */
-                        objList.add(parameter);
-                    }
-                }
-                return objList;
-            } else {
-                TableInfo tableInfo;
-                if(parameterObject instanceof java.util.Map){
-                    Object et = ((java.util.Map)parameterObject).get("et");
-                    if(et!=null){
-                        tableInfo = TableInfoHelper.getTableInfo(et.getClass());
-                    }else{
-                        tableInfo = null;
-                    }
-                }else{
-                    tableInfo = TableInfoHelper.getTableInfo(parameterObject.getClass());
-                }
-                return populateKeys(metaObjectHandler, tableInfo, ms, parameterObject);
-            }
-        }
-        return parameterObject;
-    }
-
-    /**
-     * <p>
-     * 处理正常批量插入逻辑
-     * </p>
-     * <p>
-     * org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap 该类方法
-     * wrapCollection 实现 StrictMap 封装逻辑
-     * </p>
-     *
-     * @param parameter 插入数据库对象
-     * @return
-     */
-    @SuppressWarnings({"rawtypes", "unchecked"})
-    protected static Collection<Object> getParameters(Object parameter) {
-        Collection<Object> parameters = null;
-        if (parameter instanceof Collection) {
-            parameters = (Collection) parameter;
-        } else if (parameter instanceof Map) {
-            Map parameterMap = (Map) parameter;
-            if (parameterMap.containsKey("collection")) {
-                parameters = (Collection) parameterMap.get("collection");
-            } else if (parameterMap.containsKey("list")) {
-                parameters = (List) parameterMap.get("list");
-            } else if (parameterMap.containsKey("array")) {
-                parameters = Arrays.asList((Object[]) parameterMap.get("array"));
-            }
-        }
-        return parameters;
-    }
-
-    /**
-     * <p>
-     * 自定义元对象填充控制器
-     * </p>
-     *
-     * @param metaObjectHandler 元数据填充处理器
-     * @param tableInfo         数据库表反射信息
-     * @param ms                MappedStatement
-     * @param parameterObject   插入数据库对象
-     * @return Object
-     */
-    protected static Object populateKeys(MetaObjectHandler metaObjectHandler, TableInfo tableInfo,
-                                         MappedStatement ms, Object parameterObject) {
-        if (null == tableInfo || StringUtils.isEmpty(tableInfo.getKeyProperty()) || null == tableInfo.getIdType()) {
-            /* 不处理 */
-            return parameterObject;
-        }
-        /* 自定义元对象填充控制器 */
-        MetaObject metaObject = ms.getConfiguration().newMetaObject(parameterObject);
-        if (ms.getSqlCommandType() == SqlCommandType.INSERT) {
-            if (tableInfo.getIdType().getKey() >= 2) {
-                Object idValue = metaObject.getValue(tableInfo.getKeyProperty());
-                /* 自定义 ID */
-                if (StringUtils.checkValNull(idValue)) {
-                    if (tableInfo.getIdType() == IdType.ID_WORKER) {
-                        metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.getId());
-                    } else if (tableInfo.getIdType() == IdType.UUID) {
-                        metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.get32UUID());
-                    }
-                }
-            }
-            // 插入填充
-            if (metaObjectHandler.openInsertFill()) {
-                metaObjectHandler.insertFill(metaObject);
-            }
-        } else if (ms.getSqlCommandType() == SqlCommandType.UPDATE && metaObjectHandler.openUpdateFill()) {
-            // 更新填充
-            metaObjectHandler.updateFill(metaObject);
-        }
-        return metaObject.getOriginalObject();
-    }
-
-    @SuppressWarnings({"rawtypes", "unchecked"})
-    @Override
-    public void setParameters(PreparedStatement ps) {
-        // 反射获取动态参数
-        Map<String, Object> additionalParameters = null;
-        try {
-            additionalParameters = (Map<String, Object>) additionalParametersField.get(boundSql);
-        } catch (IllegalAccessException e) {
-            // ignored, Because it will never happen.
-        }
-        ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
-        List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
-        if (parameterMappings != null) {
-            for (int i = 0; i < parameterMappings.size(); i++) {
-                ParameterMapping parameterMapping = parameterMappings.get(i);
-                if (parameterMapping.getMode() != ParameterMode.OUT) {
-                    Object value;
-                    String propertyName = parameterMapping.getProperty();
-                    if (boundSql.hasAdditionalParameter(propertyName)) {//issue#448 ask first for additional params
-                        value = boundSql.getAdditionalParameter(propertyName);
-                    } else if (parameterObject == null) {
-                        value = null;
-                    } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
-                        value = parameterObject;
-                    } else {
-                        MetaObject metaObject = configuration.newMetaObject(parameterObject);
-                        value = metaObject.getValue(propertyName);
-                        if (value == null && MapUtils.isNotEmpty(additionalParameters)) {
-                            // issue #138
-                            value = additionalParameters.get(propertyName);
-                        }
-                    }
-                    TypeHandler typeHandler = parameterMapping.getTypeHandler();
-                    JdbcType jdbcType = parameterMapping.getJdbcType();
-                    if (value == null && jdbcType == null) {
-                        jdbcType = configuration.getJdbcTypeForNull();
-                    }
-                    try {
-                        typeHandler.setParameter(ps, i + 1, value, jdbcType);
-                    } catch (TypeException | SQLException e) {
-                        throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
-                    }
-                }
-            }
-        }
-    }
-
-}
+/**
+ * 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;
+
+import java.lang.reflect.Field;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.executor.ErrorContext;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.ParameterMapping;
+import org.apache.ibatis.mapping.ParameterMode;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.reflection.MetaObject;
+import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.TypeException;
+import org.apache.ibatis.type.TypeHandler;
+import org.apache.ibatis.type.TypeHandlerRegistry;
+
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.entity.TableInfo;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+import com.baomidou.mybatisplus.toolkit.MapUtils;
+import com.baomidou.mybatisplus.toolkit.StringUtils;
+import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
+
+/**
+ * <p>
+ * 自定义 ParameterHandler 重装构造函数,填充插入方法主键 ID
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-03-11
+ */
+public class MybatisDefaultParameterHandler extends DefaultParameterHandler {
+
+    /**
+     * @see org.apache.ibatis.mapping.BoundSql
+     */
+    private static final Field additionalParametersField = getAdditionalParametersField();
+    private final TypeHandlerRegistry typeHandlerRegistry;
+    private final MappedStatement mappedStatement;
+    private final Object parameterObject;
+    private BoundSql boundSql;
+    private Configuration configuration;
+    public MybatisDefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
+        super(mappedStatement, processBatch(mappedStatement, parameterObject), boundSql);
+        this.mappedStatement = mappedStatement;
+        this.configuration = mappedStatement.getConfiguration();
+        this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
+        this.parameterObject = parameterObject;
+        this.boundSql = boundSql;
+    }
+
+    /**
+     * 反射获取BoundSql中additionalParameters参数字段
+     *
+     * @return
+     * @see org.apache.ibatis.mapping.BoundSql
+     */
+    private static Field getAdditionalParametersField() {
+        try {
+            Field additionalParametersField = BoundSql.class.getDeclaredField("additionalParameters");
+            additionalParametersField.setAccessible(true);
+            return additionalParametersField;
+        } catch (NoSuchFieldException e) {
+            // ignored, Because it will never happen.
+        }
+        return null;
+    }
+
+    /**
+     * <p>
+     * 批量(填充主键 ID)
+     * </p>
+     *
+     * @param ms
+     * @param parameterObject 插入数据库对象
+     * @return
+     */
+    protected static Object processBatch(MappedStatement ms, Object parameterObject) {
+        boolean isFill = false;
+        // 全局配置是否配置填充器
+        MetaObjectHandler metaObjectHandler = GlobalConfiguration.getMetaObjectHandler(ms.getConfiguration());
+        /* 只处理插入或更新操作 */
+        if (ms.getSqlCommandType() == SqlCommandType.INSERT) {
+            isFill = true;
+        } else if (ms.getSqlCommandType() == SqlCommandType.UPDATE
+                && metaObjectHandler.openUpdateFill()) {
+            isFill = true;
+        }
+        if (isFill) {
+            Collection<Object> parameters = getParameters(parameterObject);
+            if (null != parameters) {
+                List<Object> objList = new ArrayList<>();
+                for (Object parameter : parameters) {
+                    TableInfo tableInfo = TableInfoHelper.getTableInfo(parameter.getClass());
+                    if (null != tableInfo) {
+                        objList.add(populateKeys(metaObjectHandler, tableInfo, ms, parameter));
+                    } else {
+                        /*
+                         * 非表映射类不处理
+						 */
+                        objList.add(parameter);
+                    }
+                }
+                return objList;
+            } else {
+                TableInfo tableInfo;
+                if(parameterObject instanceof java.util.Map){
+                    Object et = ((java.util.Map)parameterObject).get("et");
+                    if(et!=null){
+                        tableInfo = TableInfoHelper.getTableInfo(et.getClass());
+                    }else{
+                        tableInfo = null;
+                    }
+                }else{
+                    tableInfo = TableInfoHelper.getTableInfo(parameterObject.getClass());
+                }
+                return populateKeys(metaObjectHandler, tableInfo, ms, parameterObject);
+            }
+        }
+        return parameterObject;
+    }
+
+    /**
+     * <p>
+     * 处理正常批量插入逻辑
+     * </p>
+     * <p>
+     * org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap 该类方法
+     * wrapCollection 实现 StrictMap 封装逻辑
+     * </p>
+     *
+     * @param parameter 插入数据库对象
+     * @return
+     */
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    protected static Collection<Object> getParameters(Object parameter) {
+        Collection<Object> parameters = null;
+        if (parameter instanceof Collection) {
+            parameters = (Collection) parameter;
+        } else if (parameter instanceof Map) {
+            Map parameterMap = (Map) parameter;
+            if (parameterMap.containsKey("collection")) {
+                parameters = (Collection) parameterMap.get("collection");
+            } else if (parameterMap.containsKey("list")) {
+                parameters = (List) parameterMap.get("list");
+            } else if (parameterMap.containsKey("array")) {
+                parameters = Arrays.asList((Object[]) parameterMap.get("array"));
+            }
+        }
+        return parameters;
+    }
+
+    /**
+     * <p>
+     * 自定义元对象填充控制器
+     * </p>
+     *
+     * @param metaObjectHandler 元数据填充处理器
+     * @param tableInfo         数据库表反射信息
+     * @param ms                MappedStatement
+     * @param parameterObject   插入数据库对象
+     * @return Object
+     */
+    protected static Object populateKeys(MetaObjectHandler metaObjectHandler, TableInfo tableInfo,
+                                         MappedStatement ms, Object parameterObject) {
+        if (null == tableInfo || StringUtils.isEmpty(tableInfo.getKeyProperty()) || null == tableInfo.getIdType()) {
+            /* 不处理 */
+            return parameterObject;
+        }
+        /* 自定义元对象填充控制器 */
+        MetaObject metaObject = ms.getConfiguration().newMetaObject(parameterObject);
+        if (ms.getSqlCommandType() == SqlCommandType.INSERT) {
+            if (tableInfo.getIdType().getKey() >= 2) {
+                Object idValue = metaObject.getValue(tableInfo.getKeyProperty());
+                /* 自定义 ID */
+                if (StringUtils.checkValNull(idValue)) {
+                    if (tableInfo.getIdType() == IdType.ID_WORKER) {
+                        metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.getId());
+                    } else if (tableInfo.getIdType() == IdType.UUID) {
+                        metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.get32UUID());
+                    }
+                }
+            }
+            // 插入填充
+            if (metaObjectHandler.openInsertFill()) {
+                metaObjectHandler.insertFill(metaObject);
+            }
+        } else if (ms.getSqlCommandType() == SqlCommandType.UPDATE && metaObjectHandler.openUpdateFill()) {
+            // 更新填充
+            metaObjectHandler.updateFill(metaObject);
+        }
+        return metaObject.getOriginalObject();
+    }
+
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    @Override
+    public void setParameters(PreparedStatement ps) {
+        // 反射获取动态参数
+        Map<String, Object> additionalParameters = null;
+        try {
+            additionalParameters = (Map<String, Object>) additionalParametersField.get(boundSql);
+        } catch (IllegalAccessException e) {
+            // ignored, Because it will never happen.
+        }
+        ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
+        List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
+        if (parameterMappings != null) {
+            for (int i = 0; i < parameterMappings.size(); i++) {
+                ParameterMapping parameterMapping = parameterMappings.get(i);
+                if (parameterMapping.getMode() != ParameterMode.OUT) {
+                    Object value;
+                    String propertyName = parameterMapping.getProperty();
+                    if (boundSql.hasAdditionalParameter(propertyName)) {//issue#448 ask first for additional params
+                        value = boundSql.getAdditionalParameter(propertyName);
+                    } else if (parameterObject == null) {
+                        value = null;
+                    } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
+                        value = parameterObject;
+                    } else {
+                        MetaObject metaObject = configuration.newMetaObject(parameterObject);
+                        value = metaObject.getValue(propertyName);
+                        if (value == null && MapUtils.isNotEmpty(additionalParameters)) {
+                            // issue #138
+                            value = additionalParameters.get(propertyName);
+                        }
+                    }
+                    TypeHandler typeHandler = parameterMapping.getTypeHandler();
+                    JdbcType jdbcType = parameterMapping.getJdbcType();
+                    if (value == null && jdbcType == null) {
+                        jdbcType = configuration.getJdbcTypeForNull();
+                    }
+                    try {
+                        typeHandler.setParameter(ps, i + 1, value, jdbcType);
+                    } catch (TypeException | SQLException e) {
+                        throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
+                    }
+                }
+            }
+        }
+    }
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisMapperAnnotationBuilder.java → src/main/java/com/baomidou/mybatisplus/MybatisMapperAnnotationBuilder.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisMapperRegistry.java → src/main/java/com/baomidou/mybatisplus/MybatisMapperRegistry.java


+ 75 - 75
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisSessionFactoryBuilder.java → src/main/java/com/baomidou/mybatisplus/MybatisSessionFactoryBuilder.java

@@ -1,75 +1,75 @@
-/**
- * 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;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.Properties;
-
-import org.apache.ibatis.exceptions.ExceptionFactory;
-import org.apache.ibatis.executor.ErrorContext;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.apache.ibatis.session.SqlSessionFactoryBuilder;
-
-import com.baomidou.mybatisplus.entity.GlobalConfiguration;
-import com.baomidou.mybatisplus.toolkit.IOUtils;
-
-/**
- * <p>
- * replace default SqlSessionFactoryBuilder class
- * </p>
- *
- * @author hubin
- * @Date 2016-01-23
- */
-public class MybatisSessionFactoryBuilder extends SqlSessionFactoryBuilder {
-
-    private GlobalConfiguration globalConfig = GlobalConfiguration.defaults();
-
-    @Override
-    public SqlSessionFactory build(Reader reader, String environment, Properties properties) {
-        try {
-            MybatisXMLConfigBuilder parser = new MybatisXMLConfigBuilder(reader, environment, properties);
-            GlobalConfiguration.setGlobalConfig(parser.getConfiguration(), this.globalConfig);
-            return build(parser.parse());
-        } catch (Exception e) {
-            throw ExceptionFactory.wrapException("Error building SqlSession.", e);
-        } finally {
-            ErrorContext.instance().reset();
-            IOUtils.closeQuietly(reader);
-        }
-    }
-
-    @Override
-    public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
-        try {
-            MybatisXMLConfigBuilder parser = new MybatisXMLConfigBuilder(inputStream, environment, properties);
-            GlobalConfiguration.setGlobalConfig(parser.getConfiguration(), this.globalConfig);
-            return build(parser.parse());
-        } catch (Exception e) {
-            throw ExceptionFactory.wrapException("Error building SqlSession.", e);
-        } finally {
-            ErrorContext.instance().reset();
-            IOUtils.closeQuietly(inputStream);
-        }
-    }
-
-    // TODO 注入全局配置
-    public void setGlobalConfig(GlobalConfiguration globalConfig) {
-        this.globalConfig = globalConfig;
-    }
-
-}
+/**
+ * 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;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Properties;
+
+import org.apache.ibatis.exceptions.ExceptionFactory;
+import org.apache.ibatis.executor.ErrorContext;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.toolkit.IOUtils;
+
+/**
+ * <p>
+ * replace default SqlSessionFactoryBuilder class
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-01-23
+ */
+public class MybatisSessionFactoryBuilder extends SqlSessionFactoryBuilder {
+
+    private GlobalConfiguration globalConfig = GlobalConfiguration.defaults();
+
+    @Override
+    public SqlSessionFactory build(Reader reader, String environment, Properties properties) {
+        try {
+            MybatisXMLConfigBuilder parser = new MybatisXMLConfigBuilder(reader, environment, properties);
+            GlobalConfiguration.setGlobalConfig(parser.getConfiguration(), this.globalConfig);
+            return build(parser.parse());
+        } catch (Exception e) {
+            throw ExceptionFactory.wrapException("Error building SqlSession.", e);
+        } finally {
+            ErrorContext.instance().reset();
+            IOUtils.closeQuietly(reader);
+        }
+    }
+
+    @Override
+    public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
+        try {
+            MybatisXMLConfigBuilder parser = new MybatisXMLConfigBuilder(inputStream, environment, properties);
+            GlobalConfiguration.setGlobalConfig(parser.getConfiguration(), this.globalConfig);
+            return build(parser.parse());
+        } catch (Exception e) {
+            throw ExceptionFactory.wrapException("Error building SqlSession.", e);
+        } finally {
+            ErrorContext.instance().reset();
+            IOUtils.closeQuietly(inputStream);
+        }
+    }
+
+    // TODO 注入全局配置
+    public void setGlobalConfig(GlobalConfiguration globalConfig) {
+        this.globalConfig = globalConfig;
+    }
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisSqlSessionTemplate.java → src/main/java/com/baomidou/mybatisplus/MybatisSqlSessionTemplate.java


+ 438 - 438
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisXMLConfigBuilder.java → src/main/java/com/baomidou/mybatisplus/MybatisXMLConfigBuilder.java

@@ -1,438 +1,438 @@
-/**
- * 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;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.sql.DataSource;
-
-import org.apache.ibatis.builder.BaseBuilder;
-import org.apache.ibatis.builder.BuilderException;
-import org.apache.ibatis.builder.xml.XMLMapperEntityResolver;
-import org.apache.ibatis.datasource.DataSourceFactory;
-import org.apache.ibatis.executor.ErrorContext;
-import org.apache.ibatis.executor.loader.ProxyFactory;
-import org.apache.ibatis.io.ResolverUtil;
-import org.apache.ibatis.io.Resources;
-import org.apache.ibatis.io.VFS;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.mapping.DatabaseIdProvider;
-import org.apache.ibatis.mapping.Environment;
-import org.apache.ibatis.parsing.XNode;
-import org.apache.ibatis.parsing.XPathParser;
-import org.apache.ibatis.plugin.Interceptor;
-import org.apache.ibatis.reflection.DefaultReflectorFactory;
-import org.apache.ibatis.reflection.MetaClass;
-import org.apache.ibatis.reflection.ReflectorFactory;
-import org.apache.ibatis.reflection.factory.ObjectFactory;
-import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
-import org.apache.ibatis.session.AutoMappingBehavior;
-import org.apache.ibatis.session.AutoMappingUnknownColumnBehavior;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.session.ExecutorType;
-import org.apache.ibatis.session.LocalCacheScope;
-import org.apache.ibatis.transaction.TransactionFactory;
-import org.apache.ibatis.type.JdbcType;
-
-/**
- * <p>
- * Copy from XMLConfigBuilder in Mybatis and replace default Configuration class
- * by MybatisConfiguration class
- * </p>
- *
- * @author hubin
- * @Date 2017-01-04
- */
-public class MybatisXMLConfigBuilder extends BaseBuilder {
-
-    private boolean parsed;
-    private XPathParser parser;
-    private String environment;
-    private ReflectorFactory localReflectorFactory = new DefaultReflectorFactory();
-
-    public MybatisXMLConfigBuilder(Reader reader) {
-        this(reader, null, null);
-    }
-
-    public MybatisXMLConfigBuilder(Reader reader, String environment) {
-        this(reader, environment, null);
-    }
-
-    public MybatisXMLConfigBuilder(Reader reader, String environment, Properties props) {
-        this(new XPathParser(reader, true, props, new XMLMapperEntityResolver()), environment, props);
-    }
-
-    public MybatisXMLConfigBuilder(InputStream inputStream) {
-        this(inputStream, null, null);
-    }
-
-    public MybatisXMLConfigBuilder(InputStream inputStream, String environment) {
-        this(inputStream, environment, null);
-    }
-
-    public MybatisXMLConfigBuilder(InputStream inputStream, String environment, Properties props) {
-        this(new XPathParser(inputStream, true, props, new XMLMapperEntityResolver()), environment, props);
-    }
-
-    private MybatisXMLConfigBuilder(XPathParser parser, String environment, Properties props) {
-        //TODO 自定义 Configuration
-        super(new MybatisConfiguration());
-        ErrorContext.instance().resource("SQL Mapper Configuration");
-        this.configuration.setVariables(props);
-        this.parsed = false;
-        this.environment = environment;
-        this.parser = parser;
-    }
-
-    public Configuration parse() {
-        if (parsed) {
-            throw new BuilderException("Each XMLConfigBuilder can only be used once.");
-        }
-        parsed = true;
-        parseConfiguration(parser.evalNode("/configuration"));
-        return configuration;
-    }
-
-    private void parseConfiguration(XNode root) {
-        try {
-            //issue #117 read properties first
-            propertiesElement(root.evalNode("properties"));
-            Properties settings = settingsAsProperties(root.evalNode("settings"));
-            loadCustomVfs(settings);
-            typeAliasesElement(root.evalNode("typeAliases"));
-            pluginElement(root.evalNode("plugins"));
-            objectFactoryElement(root.evalNode("objectFactory"));
-            objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
-            reflectorFactoryElement(root.evalNode("reflectorFactory"));
-            settingsElement(settings);
-            // read it after objectFactory and objectWrapperFactory issue #631
-            environmentsElement(root.evalNode("environments"));
-            databaseIdProviderElement(root.evalNode("databaseIdProvider"));
-            typeHandlerElement(root.evalNode("typeHandlers"));
-            mapperElement(root.evalNode("mappers"));
-        } catch (Exception e) {
-            throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);
-        }
-    }
-
-    private Properties settingsAsProperties(XNode context) {
-        if (context == null) {
-            return new Properties();
-        }
-        Properties props = context.getChildrenAsProperties();
-        // Check that all settings are known to the configuration class
-        MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory);
-        for (Object key : props.keySet()) {
-            if (!metaConfig.hasSetter(String.valueOf(key))) {
-                throw new BuilderException("The setting " + key + " is not known.  Make sure you spelled it correctly (case sensitive).");
-            }
-        }
-        return props;
-    }
-
-    private void loadCustomVfs(Properties props) throws ClassNotFoundException {
-        String value = props.getProperty("vfsImpl");
-        if (value != null) {
-            String[] clazzes = value.split(",");
-            for (String clazz : clazzes) {
-                if (!clazz.isEmpty()) {
-                    @SuppressWarnings("unchecked")
-                    Class<? extends VFS> vfsImpl = (Class<? extends VFS>) Resources.classForName(clazz);
-                    configuration.setVfsImpl(vfsImpl);
-                }
-            }
-        }
-    }
-
-    private void typeAliasesElement(XNode parent) {
-        if (parent != null) {
-            for (XNode child : parent.getChildren()) {
-                if ("package".equals(child.getName())) {
-                    String typeAliasPackage = child.getStringAttribute("name");
-                    configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
-                } else {
-                    String alias = child.getStringAttribute("alias");
-                    String type = child.getStringAttribute("type");
-                    try {
-                        Class<?> clazz = Resources.classForName(type);
-                        if (alias == null) {
-                            typeAliasRegistry.registerAlias(clazz);
-                        } else {
-                            typeAliasRegistry.registerAlias(alias, clazz);
-                        }
-                    } catch (ClassNotFoundException e) {
-                        throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
-                    }
-                }
-            }
-        }
-    }
-
-    private void pluginElement(XNode parent) throws Exception {
-        if (parent != null) {
-            for (XNode child : parent.getChildren()) {
-                String interceptor = child.getStringAttribute("interceptor");
-                Properties properties = child.getChildrenAsProperties();
-                Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
-                interceptorInstance.setProperties(properties);
-                configuration.addInterceptor(interceptorInstance);
-            }
-        }
-    }
-
-    private void objectFactoryElement(XNode context) throws Exception {
-        if (context != null) {
-            String type = context.getStringAttribute("type");
-            Properties properties = context.getChildrenAsProperties();
-            ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
-            factory.setProperties(properties);
-            configuration.setObjectFactory(factory);
-        }
-    }
-
-    private void objectWrapperFactoryElement(XNode context) throws Exception {
-        if (context != null) {
-            String type = context.getStringAttribute("type");
-            ObjectWrapperFactory factory = (ObjectWrapperFactory) resolveClass(type).newInstance();
-            configuration.setObjectWrapperFactory(factory);
-        }
-    }
-
-    private void reflectorFactoryElement(XNode context) throws Exception {
-        if (context != null) {
-            String type = context.getStringAttribute("type");
-            ReflectorFactory factory = (ReflectorFactory) resolveClass(type).newInstance();
-            configuration.setReflectorFactory(factory);
-        }
-    }
-
-    private void propertiesElement(XNode context) throws Exception {
-        if (context != null) {
-            Properties defaults = context.getChildrenAsProperties();
-            String resource = context.getStringAttribute("resource");
-            String url = context.getStringAttribute("url");
-            if (resource != null && url != null) {
-                throw new BuilderException("The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
-            }
-            if (resource != null) {
-                defaults.putAll(Resources.getResourceAsProperties(resource));
-            } else if (url != null) {
-                defaults.putAll(Resources.getUrlAsProperties(url));
-            }
-            Properties vars = configuration.getVariables();
-            if (vars != null) {
-                defaults.putAll(vars);
-            }
-            parser.setVariables(defaults);
-            configuration.setVariables(defaults);
-        }
-    }
-
-    private void settingsElement(Properties props) throws Exception {
-        configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
-        configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
-        configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
-        configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
-        configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
-        configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), false));
-        configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
-        configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
-        configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
-        configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
-        configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
-        configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
-        configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
-        configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
-        configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
-        configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
-        configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
-        configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
-        configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
-        configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
-        configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
-        configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false));
-        configuration.setLogPrefix(props.getProperty("logPrefix"));
-        @SuppressWarnings("unchecked")
-        Class<? extends Log> logImpl = (Class<? extends Log>) resolveClass(props.getProperty("logImpl"));
-        configuration.setLogImpl(logImpl);
-        configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
-    }
-
-    private void environmentsElement(XNode context) throws Exception {
-        if (context != null) {
-            if (environment == null) {
-                environment = context.getStringAttribute("default");
-            }
-            for (XNode child : context.getChildren()) {
-                String id = child.getStringAttribute("id");
-                if (isSpecifiedEnvironment(id)) {
-                    TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager"));
-                    DataSourceFactory dsFactory = dataSourceElement(child.evalNode("dataSource"));
-                    DataSource dataSource = dsFactory.getDataSource();
-                    Environment.Builder environmentBuilder = new Environment.Builder(id)
-                            .transactionFactory(txFactory)
-                            .dataSource(dataSource);
-                    configuration.setEnvironment(environmentBuilder.build());
-                }
-            }
-        }
-    }
-
-    private void databaseIdProviderElement(XNode context) throws Exception {
-        DatabaseIdProvider databaseIdProvider = null;
-        if (context != null) {
-            String type = context.getStringAttribute("type");
-            // awful patch to keep backward compatibility
-            if ("VENDOR".equals(type)) {
-                type = "DB_VENDOR";
-            }
-            Properties properties = context.getChildrenAsProperties();
-            databaseIdProvider = (DatabaseIdProvider) resolveClass(type).newInstance();
-            databaseIdProvider.setProperties(properties);
-        }
-        Environment environment = configuration.getEnvironment();
-        if (environment != null && databaseIdProvider != null) {
-            String databaseId = databaseIdProvider.getDatabaseId(environment.getDataSource());
-            configuration.setDatabaseId(databaseId);
-        }
-    }
-
-    private TransactionFactory transactionManagerElement(XNode context) throws Exception {
-        if (context != null) {
-            String type = context.getStringAttribute("type");
-            Properties props = context.getChildrenAsProperties();
-            TransactionFactory factory = (TransactionFactory) resolveClass(type).newInstance();
-            factory.setProperties(props);
-            return factory;
-        }
-        throw new BuilderException("Environment declaration requires a TransactionFactory.");
-    }
-
-    private DataSourceFactory dataSourceElement(XNode context) throws Exception {
-        if (context != null) {
-            String type = context.getStringAttribute("type");
-            Properties props = context.getChildrenAsProperties();
-            DataSourceFactory factory = (DataSourceFactory) resolveClass(type).newInstance();
-            factory.setProperties(props);
-            return factory;
-        }
-        throw new BuilderException("Environment declaration requires a DataSourceFactory.");
-    }
-
-    private void typeHandlerElement(XNode parent) throws Exception {
-        if (parent != null) {
-            for (XNode child : parent.getChildren()) {
-                if ("package".equals(child.getName())) {
-                    String typeHandlerPackage = child.getStringAttribute("name");
-                    typeHandlerRegistry.register(typeHandlerPackage);
-                } else {
-                    String javaTypeName = child.getStringAttribute("javaType");
-                    String jdbcTypeName = child.getStringAttribute("jdbcType");
-                    String handlerTypeName = child.getStringAttribute("handler");
-                    Class<?> javaTypeClass = resolveClass(javaTypeName);
-                    JdbcType jdbcType = resolveJdbcType(jdbcTypeName);
-                    Class<?> typeHandlerClass = resolveClass(handlerTypeName);
-                    if (javaTypeClass != null) {
-                        if (jdbcType == null) {
-                            typeHandlerRegistry.register(javaTypeClass, typeHandlerClass);
-                        } else {
-                            typeHandlerRegistry.register(javaTypeClass, jdbcType, typeHandlerClass);
-                        }
-                    } else {
-                        typeHandlerRegistry.register(typeHandlerClass);
-                    }
-                }
-            }
-        }
-    }
-
-    private void mapperElement(XNode parent) throws Exception {
-        /**
-         * 定义集合 用来分类放置mybatis的Mapper与XML 按顺序依次遍历
-         */
-        if (parent != null) {
-            //指定在classpath中的mapper文件
-            Set<String> resources = new HashSet<>();
-            //指向一个mapper接口
-            Set<Class<?>> mapperClasses = new HashSet<>();
-            setResource(parent, resources, mapperClasses);
-            // 依次遍历 首先 resource 然后 mapper
-            for (String resource : resources) {
-                ErrorContext.instance().resource(resource);
-                InputStream inputStream = Resources.getResourceAsStream(resource);
-                //TODO
-                MybatisXMLMapperBuilder mapperParser = new MybatisXMLMapperBuilder(inputStream, configuration, resource,
-                        configuration.getSqlFragments());
-                mapperParser.parse();
-            }
-            for (Class<?> mapper : mapperClasses) {
-                //TODO
-                configuration.addMapper(mapper);
-            }
-        }
-    }
-
-    /**
-     * 查找mybatis配置文件填充至Set集合
-     *
-     * @param parent    节点
-     * @param resources
-     * @param mapper
-     * @throws ClassNotFoundException
-     */
-    private void setResource(XNode parent, Set<String> resources, Set<Class<?>> mapper) throws ClassNotFoundException {
-        for (XNode child : parent.getChildren()) {
-            if ("package".equals(child.getName())) {
-                String mapperPackage = child.getStringAttribute("name");
-                ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<>();
-                resolverUtil.find(new ResolverUtil.IsA(Object.class), mapperPackage);
-                Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
-                mapper.addAll(mapperSet);
-            } else {
-                String resource = child.getStringAttribute("resource");
-                String url = child.getStringAttribute("url");
-                String mapperClass = child.getStringAttribute("class");
-                if (resource != null && url == null && mapperClass == null) {
-                    resources.add(resource);
-                } else if (resource == null && url != null && mapperClass == null) {
-                    resources.add(url);
-                } else if (resource == null && url == null && mapperClass != null) {
-                    Class<?> mapperInterface = Resources.classForName(mapperClass);
-                    mapper.add(mapperInterface);
-                } else {
-                    throw new BuilderException(
-                            "A mapper element may only specify a url, resource or class, but not more than one.");
-                }
-            }
-        }
-    }
-
-    private boolean isSpecifiedEnvironment(String id) {
-        if (environment == null) {
-            throw new BuilderException("No environment specified.");
-        } else if (id == null) {
-            throw new BuilderException("Environment requires an id attribute.");
-        } else if (environment.equals(id)) {
-            return true;
-        }
-        return false;
-    }
-
-}
+/**
+ * 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;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.sql.DataSource;
+
+import org.apache.ibatis.builder.BaseBuilder;
+import org.apache.ibatis.builder.BuilderException;
+import org.apache.ibatis.builder.xml.XMLMapperEntityResolver;
+import org.apache.ibatis.datasource.DataSourceFactory;
+import org.apache.ibatis.executor.ErrorContext;
+import org.apache.ibatis.executor.loader.ProxyFactory;
+import org.apache.ibatis.io.ResolverUtil;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.io.VFS;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.mapping.DatabaseIdProvider;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.parsing.XNode;
+import org.apache.ibatis.parsing.XPathParser;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.reflection.DefaultReflectorFactory;
+import org.apache.ibatis.reflection.MetaClass;
+import org.apache.ibatis.reflection.ReflectorFactory;
+import org.apache.ibatis.reflection.factory.ObjectFactory;
+import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
+import org.apache.ibatis.session.AutoMappingBehavior;
+import org.apache.ibatis.session.AutoMappingUnknownColumnBehavior;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.LocalCacheScope;
+import org.apache.ibatis.transaction.TransactionFactory;
+import org.apache.ibatis.type.JdbcType;
+
+/**
+ * <p>
+ * Copy from XMLConfigBuilder in Mybatis and replace default Configuration class
+ * by MybatisConfiguration class
+ * </p>
+ *
+ * @author hubin
+ * @Date 2017-01-04
+ */
+public class MybatisXMLConfigBuilder extends BaseBuilder {
+
+    private boolean parsed;
+    private XPathParser parser;
+    private String environment;
+    private ReflectorFactory localReflectorFactory = new DefaultReflectorFactory();
+
+    public MybatisXMLConfigBuilder(Reader reader) {
+        this(reader, null, null);
+    }
+
+    public MybatisXMLConfigBuilder(Reader reader, String environment) {
+        this(reader, environment, null);
+    }
+
+    public MybatisXMLConfigBuilder(Reader reader, String environment, Properties props) {
+        this(new XPathParser(reader, true, props, new XMLMapperEntityResolver()), environment, props);
+    }
+
+    public MybatisXMLConfigBuilder(InputStream inputStream) {
+        this(inputStream, null, null);
+    }
+
+    public MybatisXMLConfigBuilder(InputStream inputStream, String environment) {
+        this(inputStream, environment, null);
+    }
+
+    public MybatisXMLConfigBuilder(InputStream inputStream, String environment, Properties props) {
+        this(new XPathParser(inputStream, true, props, new XMLMapperEntityResolver()), environment, props);
+    }
+
+    private MybatisXMLConfigBuilder(XPathParser parser, String environment, Properties props) {
+        //TODO 自定义 Configuration
+        super(new MybatisConfiguration());
+        ErrorContext.instance().resource("SQL Mapper Configuration");
+        this.configuration.setVariables(props);
+        this.parsed = false;
+        this.environment = environment;
+        this.parser = parser;
+    }
+
+    public Configuration parse() {
+        if (parsed) {
+            throw new BuilderException("Each XMLConfigBuilder can only be used once.");
+        }
+        parsed = true;
+        parseConfiguration(parser.evalNode("/configuration"));
+        return configuration;
+    }
+
+    private void parseConfiguration(XNode root) {
+        try {
+            //issue #117 read properties first
+            propertiesElement(root.evalNode("properties"));
+            Properties settings = settingsAsProperties(root.evalNode("settings"));
+            loadCustomVfs(settings);
+            typeAliasesElement(root.evalNode("typeAliases"));
+            pluginElement(root.evalNode("plugins"));
+            objectFactoryElement(root.evalNode("objectFactory"));
+            objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
+            reflectorFactoryElement(root.evalNode("reflectorFactory"));
+            settingsElement(settings);
+            // read it after objectFactory and objectWrapperFactory issue #631
+            environmentsElement(root.evalNode("environments"));
+            databaseIdProviderElement(root.evalNode("databaseIdProvider"));
+            typeHandlerElement(root.evalNode("typeHandlers"));
+            mapperElement(root.evalNode("mappers"));
+        } catch (Exception e) {
+            throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);
+        }
+    }
+
+    private Properties settingsAsProperties(XNode context) {
+        if (context == null) {
+            return new Properties();
+        }
+        Properties props = context.getChildrenAsProperties();
+        // Check that all settings are known to the configuration class
+        MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory);
+        for (Object key : props.keySet()) {
+            if (!metaConfig.hasSetter(String.valueOf(key))) {
+                throw new BuilderException("The setting " + key + " is not known.  Make sure you spelled it correctly (case sensitive).");
+            }
+        }
+        return props;
+    }
+
+    private void loadCustomVfs(Properties props) throws ClassNotFoundException {
+        String value = props.getProperty("vfsImpl");
+        if (value != null) {
+            String[] clazzes = value.split(",");
+            for (String clazz : clazzes) {
+                if (!clazz.isEmpty()) {
+                    @SuppressWarnings("unchecked")
+                    Class<? extends VFS> vfsImpl = (Class<? extends VFS>) Resources.classForName(clazz);
+                    configuration.setVfsImpl(vfsImpl);
+                }
+            }
+        }
+    }
+
+    private void typeAliasesElement(XNode parent) {
+        if (parent != null) {
+            for (XNode child : parent.getChildren()) {
+                if ("package".equals(child.getName())) {
+                    String typeAliasPackage = child.getStringAttribute("name");
+                    configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
+                } else {
+                    String alias = child.getStringAttribute("alias");
+                    String type = child.getStringAttribute("type");
+                    try {
+                        Class<?> clazz = Resources.classForName(type);
+                        if (alias == null) {
+                            typeAliasRegistry.registerAlias(clazz);
+                        } else {
+                            typeAliasRegistry.registerAlias(alias, clazz);
+                        }
+                    } catch (ClassNotFoundException e) {
+                        throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
+                    }
+                }
+            }
+        }
+    }
+
+    private void pluginElement(XNode parent) throws Exception {
+        if (parent != null) {
+            for (XNode child : parent.getChildren()) {
+                String interceptor = child.getStringAttribute("interceptor");
+                Properties properties = child.getChildrenAsProperties();
+                Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
+                interceptorInstance.setProperties(properties);
+                configuration.addInterceptor(interceptorInstance);
+            }
+        }
+    }
+
+    private void objectFactoryElement(XNode context) throws Exception {
+        if (context != null) {
+            String type = context.getStringAttribute("type");
+            Properties properties = context.getChildrenAsProperties();
+            ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
+            factory.setProperties(properties);
+            configuration.setObjectFactory(factory);
+        }
+    }
+
+    private void objectWrapperFactoryElement(XNode context) throws Exception {
+        if (context != null) {
+            String type = context.getStringAttribute("type");
+            ObjectWrapperFactory factory = (ObjectWrapperFactory) resolveClass(type).newInstance();
+            configuration.setObjectWrapperFactory(factory);
+        }
+    }
+
+    private void reflectorFactoryElement(XNode context) throws Exception {
+        if (context != null) {
+            String type = context.getStringAttribute("type");
+            ReflectorFactory factory = (ReflectorFactory) resolveClass(type).newInstance();
+            configuration.setReflectorFactory(factory);
+        }
+    }
+
+    private void propertiesElement(XNode context) throws Exception {
+        if (context != null) {
+            Properties defaults = context.getChildrenAsProperties();
+            String resource = context.getStringAttribute("resource");
+            String url = context.getStringAttribute("url");
+            if (resource != null && url != null) {
+                throw new BuilderException("The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
+            }
+            if (resource != null) {
+                defaults.putAll(Resources.getResourceAsProperties(resource));
+            } else if (url != null) {
+                defaults.putAll(Resources.getUrlAsProperties(url));
+            }
+            Properties vars = configuration.getVariables();
+            if (vars != null) {
+                defaults.putAll(vars);
+            }
+            parser.setVariables(defaults);
+            configuration.setVariables(defaults);
+        }
+    }
+
+    private void settingsElement(Properties props) throws Exception {
+        configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
+        configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
+        configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
+        configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
+        configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
+        configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), false));
+        configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
+        configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
+        configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
+        configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
+        configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
+        configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
+        configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
+        configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
+        configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
+        configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
+        configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
+        configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
+        configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
+        configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
+        configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
+        configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false));
+        configuration.setLogPrefix(props.getProperty("logPrefix"));
+        @SuppressWarnings("unchecked")
+        Class<? extends Log> logImpl = (Class<? extends Log>) resolveClass(props.getProperty("logImpl"));
+        configuration.setLogImpl(logImpl);
+        configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
+    }
+
+    private void environmentsElement(XNode context) throws Exception {
+        if (context != null) {
+            if (environment == null) {
+                environment = context.getStringAttribute("default");
+            }
+            for (XNode child : context.getChildren()) {
+                String id = child.getStringAttribute("id");
+                if (isSpecifiedEnvironment(id)) {
+                    TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager"));
+                    DataSourceFactory dsFactory = dataSourceElement(child.evalNode("dataSource"));
+                    DataSource dataSource = dsFactory.getDataSource();
+                    Environment.Builder environmentBuilder = new Environment.Builder(id)
+                            .transactionFactory(txFactory)
+                            .dataSource(dataSource);
+                    configuration.setEnvironment(environmentBuilder.build());
+                }
+            }
+        }
+    }
+
+    private void databaseIdProviderElement(XNode context) throws Exception {
+        DatabaseIdProvider databaseIdProvider = null;
+        if (context != null) {
+            String type = context.getStringAttribute("type");
+            // awful patch to keep backward compatibility
+            if ("VENDOR".equals(type)) {
+                type = "DB_VENDOR";
+            }
+            Properties properties = context.getChildrenAsProperties();
+            databaseIdProvider = (DatabaseIdProvider) resolveClass(type).newInstance();
+            databaseIdProvider.setProperties(properties);
+        }
+        Environment environment = configuration.getEnvironment();
+        if (environment != null && databaseIdProvider != null) {
+            String databaseId = databaseIdProvider.getDatabaseId(environment.getDataSource());
+            configuration.setDatabaseId(databaseId);
+        }
+    }
+
+    private TransactionFactory transactionManagerElement(XNode context) throws Exception {
+        if (context != null) {
+            String type = context.getStringAttribute("type");
+            Properties props = context.getChildrenAsProperties();
+            TransactionFactory factory = (TransactionFactory) resolveClass(type).newInstance();
+            factory.setProperties(props);
+            return factory;
+        }
+        throw new BuilderException("Environment declaration requires a TransactionFactory.");
+    }
+
+    private DataSourceFactory dataSourceElement(XNode context) throws Exception {
+        if (context != null) {
+            String type = context.getStringAttribute("type");
+            Properties props = context.getChildrenAsProperties();
+            DataSourceFactory factory = (DataSourceFactory) resolveClass(type).newInstance();
+            factory.setProperties(props);
+            return factory;
+        }
+        throw new BuilderException("Environment declaration requires a DataSourceFactory.");
+    }
+
+    private void typeHandlerElement(XNode parent) throws Exception {
+        if (parent != null) {
+            for (XNode child : parent.getChildren()) {
+                if ("package".equals(child.getName())) {
+                    String typeHandlerPackage = child.getStringAttribute("name");
+                    typeHandlerRegistry.register(typeHandlerPackage);
+                } else {
+                    String javaTypeName = child.getStringAttribute("javaType");
+                    String jdbcTypeName = child.getStringAttribute("jdbcType");
+                    String handlerTypeName = child.getStringAttribute("handler");
+                    Class<?> javaTypeClass = resolveClass(javaTypeName);
+                    JdbcType jdbcType = resolveJdbcType(jdbcTypeName);
+                    Class<?> typeHandlerClass = resolveClass(handlerTypeName);
+                    if (javaTypeClass != null) {
+                        if (jdbcType == null) {
+                            typeHandlerRegistry.register(javaTypeClass, typeHandlerClass);
+                        } else {
+                            typeHandlerRegistry.register(javaTypeClass, jdbcType, typeHandlerClass);
+                        }
+                    } else {
+                        typeHandlerRegistry.register(typeHandlerClass);
+                    }
+                }
+            }
+        }
+    }
+
+    private void mapperElement(XNode parent) throws Exception {
+        /**
+         * 定义集合 用来分类放置mybatis的Mapper与XML 按顺序依次遍历
+         */
+        if (parent != null) {
+            //指定在classpath中的mapper文件
+            Set<String> resources = new HashSet<>();
+            //指向一个mapper接口
+            Set<Class<?>> mapperClasses = new HashSet<>();
+            setResource(parent, resources, mapperClasses);
+            // 依次遍历 首先 resource 然后 mapper
+            for (String resource : resources) {
+                ErrorContext.instance().resource(resource);
+                InputStream inputStream = Resources.getResourceAsStream(resource);
+                //TODO
+                MybatisXMLMapperBuilder mapperParser = new MybatisXMLMapperBuilder(inputStream, configuration, resource,
+                        configuration.getSqlFragments());
+                mapperParser.parse();
+            }
+            for (Class<?> mapper : mapperClasses) {
+                //TODO
+                configuration.addMapper(mapper);
+            }
+        }
+    }
+
+    /**
+     * 查找mybatis配置文件填充至Set集合
+     *
+     * @param parent    节点
+     * @param resources
+     * @param mapper
+     * @throws ClassNotFoundException
+     */
+    private void setResource(XNode parent, Set<String> resources, Set<Class<?>> mapper) throws ClassNotFoundException {
+        for (XNode child : parent.getChildren()) {
+            if ("package".equals(child.getName())) {
+                String mapperPackage = child.getStringAttribute("name");
+                ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<>();
+                resolverUtil.find(new ResolverUtil.IsA(Object.class), mapperPackage);
+                Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
+                mapper.addAll(mapperSet);
+            } else {
+                String resource = child.getStringAttribute("resource");
+                String url = child.getStringAttribute("url");
+                String mapperClass = child.getStringAttribute("class");
+                if (resource != null && url == null && mapperClass == null) {
+                    resources.add(resource);
+                } else if (resource == null && url != null && mapperClass == null) {
+                    resources.add(url);
+                } else if (resource == null && url == null && mapperClass != null) {
+                    Class<?> mapperInterface = Resources.classForName(mapperClass);
+                    mapper.add(mapperInterface);
+                } else {
+                    throw new BuilderException(
+                            "A mapper element may only specify a url, resource or class, but not more than one.");
+                }
+            }
+        }
+    }
+
+    private boolean isSpecifiedEnvironment(String id) {
+        if (environment == null) {
+            throw new BuilderException("No environment specified.");
+        } else if (id == null) {
+            throw new BuilderException("Environment requires an id attribute.");
+        } else if (environment.equals(id)) {
+            return true;
+        }
+        return false;
+    }
+
+}

+ 39 - 39
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisXMLLanguageDriver.java → src/main/java/com/baomidou/mybatisplus/MybatisXMLLanguageDriver.java

@@ -1,39 +1,39 @@
-/**
- * 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;
-
-import org.apache.ibatis.executor.parameter.ParameterHandler;
-import org.apache.ibatis.mapping.BoundSql;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
-
-/**
- * <p>
- * 继承 XMLLanguageDriver 重装构造函数,使用自定义 ParameterHandler
- * </p>
- *
- * @author hubin
- * @Date 2016-03-11
- */
-public class MybatisXMLLanguageDriver extends XMLLanguageDriver {
-
-    @Override
-    public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject,
-                                                   BoundSql boundSql) {
-        /* 使用自定义 ParameterHandler */
-        return new MybatisDefaultParameterHandler(mappedStatement, parameterObject, boundSql);
-    }
-}
+/**
+ * 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;
+
+import org.apache.ibatis.executor.parameter.ParameterHandler;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
+
+/**
+ * <p>
+ * 继承 XMLLanguageDriver 重装构造函数,使用自定义 ParameterHandler
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-03-11
+ */
+public class MybatisXMLLanguageDriver extends XMLLanguageDriver {
+
+    @Override
+    public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject,
+                                                   BoundSql boundSql) {
+        /* 使用自定义 ParameterHandler */
+        return new MybatisDefaultParameterHandler(mappedStatement, parameterObject, boundSql);
+    }
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisXMLMapperBuilder.java → src/main/java/com/baomidou/mybatisplus/MybatisXMLMapperBuilder.java


+ 398 - 398
mybatis-plus/src/main/java/com/baomidou/mybatisplus/activerecord/Model.java → src/main/java/com/baomidou/mybatisplus/activerecord/Model.java

@@ -1,398 +1,398 @@
-/**
- * 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.activerecord;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.ibatis.session.SqlSession;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.baomidou.mybatisplus.enums.SqlMethod;
-import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
-import com.baomidou.mybatisplus.mapper.Condition;
-import com.baomidou.mybatisplus.mapper.SqlHelper;
-import com.baomidou.mybatisplus.mapper.SqlRunner;
-import com.baomidou.mybatisplus.mapper.Wrapper;
-import com.baomidou.mybatisplus.plugins.Page;
-import com.baomidou.mybatisplus.toolkit.StringUtils;
-
-/**
- * <p>
- * ActiveRecord 模式 CRUD
- * </p>
- *
- * @param <T>
- * @author hubin
- * @Date 2016-11-06
- */
-@SuppressWarnings({"rawtypes"})
-public abstract class Model<T extends Model> implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * <p>
-     * 插入(字段选择插入)
-     * </p>
-     */
-    @Transactional
-    public boolean insert() {
-        return SqlHelper.retBool(sqlSession().insert(sqlStatement(SqlMethod.INSERT_ONE), this));
-    }
-
-    /**
-     * <p>
-     * 插入(所有字段插入)
-     * </p>
-     */
-    @Transactional
-    public boolean insertAllColumn() {
-        return SqlHelper.retBool(sqlSession().insert(sqlStatement(SqlMethod.INSERT_ONE_ALL_COLUMN), this));
-    }
-
-    /**
-     * <p>
-     * 插入 OR 更新
-     * </p>
-     */
-    @Transactional
-    public boolean insertOrUpdate() {
-        if (StringUtils.checkValNull(pkVal())) {
-            // insert
-            return insert();
-        } else {
-            /*
-             * 更新成功直接返回,失败执行插入逻辑
-			 */
-            return updateById() || insert();
-        }
-    }
-
-    /**
-     * <p>
-     * 根据 ID 删除
-     * </p>
-     *
-     * @param id 主键ID
-     * @return
-     */
-    @Transactional
-    public boolean deleteById(Serializable id) {
-        return SqlHelper.retBool(sqlSession().delete(sqlStatement(SqlMethod.DELETE_BY_ID), id));
-    }
-
-    /**
-     * <p>
-     * 根据主键删除
-     * </p>
-     *
-     * @return
-     */
-    @Transactional
-    public boolean deleteById() {
-        if (StringUtils.checkValNull(pkVal())) {
-            throw new MybatisPlusException("deleteById primaryKey is null.");
-        }
-        return deleteById(this.pkVal());
-    }
-
-    /**
-     * <p>
-     * 删除记录
-     * </p>
-     *
-     * @param whereClause 查询条件
-     * @param args        查询条件值
-     * @return
-     */
-    @Transactional
-    public boolean delete(String whereClause, Object... args) {
-        return delete(Condition.create().where(whereClause, args));
-    }
-
-    /**
-     * <p>
-     * 删除记录
-     * </p>
-     *
-     * @param wrapper
-     * @return
-     */
-    @Transactional
-    public boolean delete(Wrapper wrapper) {
-        Map<String, Object> map = new HashMap<>();
-        // delete
-        map.put("ew", wrapper);
-        return SqlHelper.retBool(sqlSession().delete(sqlStatement(SqlMethod.DELETE), map));
-    }
-
-    /**
-     * <p>
-     * 更新(字段选择更新)
-     * </p>
-     */
-    @Transactional
-    public boolean updateById() {
-        if (StringUtils.checkValNull(pkVal())) {
-            throw new MybatisPlusException("updateById primaryKey is null.");
-        }
-        // updateById
-        return SqlHelper.retBool(sqlSession().update(sqlStatement(SqlMethod.UPDATE_BY_ID), this));
-    }
-
-    /**
-     * <p>
-     * 更新(所有字段更新)
-     * </p>
-     */
-    @Transactional
-    public boolean updateAllColumnById() {
-        if (StringUtils.checkValNull(pkVal())) {
-            throw new MybatisPlusException("updateAllColumnById primaryKey is null.");
-        }
-        // updateById
-        return SqlHelper.retBool(sqlSession().update(sqlStatement(SqlMethod.UPDATE_ALL_COLUMN_BY_ID), this));
-    }
-
-    /**
-     * <p>
-     * 执行 SQL 更新
-     * </p>
-     *
-     * @param whereClause 查询条件
-     * @param args        查询条件值
-     * @return
-     */
-    @Transactional
-    public boolean update(String whereClause, Object... args) {
-        // update
-        return update(Condition.create().where(whereClause, args));
-    }
-
-    /**
-     * <p>
-     * 执行 SQL 更新
-     * </p>
-     *
-     * @param wrapper
-     * @return
-     */
-    @Transactional
-    public boolean update(Wrapper wrapper) {
-        Map<String, Object> map = new HashMap<>();
-        map.put("et", this);
-        map.put("ew", wrapper);
-        // update
-        return SqlHelper.retBool(sqlSession().update(sqlStatement(SqlMethod.UPDATE), map));
-    }
-
-    /**
-     * <p>
-     * 查询所有
-     * </p>
-     *
-     * @return
-     */
-    public List<T> selectAll() {
-        return sqlSession().selectList(sqlStatement(SqlMethod.SELECT_LIST));
-    }
-
-    /**
-     * <p>
-     * 根据 ID 查询
-     * </p>
-     *
-     * @param id 主键ID
-     * @return
-     */
-    public T selectById(Serializable id) {
-        return sqlSession().selectOne(sqlStatement(SqlMethod.SELECT_BY_ID), id);
-    }
-
-    /**
-     * <p>
-     * 根据主键查询
-     * </p>
-     *
-     * @return
-     */
-    public T selectById() {
-        if (StringUtils.checkValNull(pkVal())) {
-            throw new MybatisPlusException("selectById primaryKey is null.");
-        }
-        return selectById(this.pkVal());
-    }
-
-    /**
-     * <p>
-     * 查询总记录数
-     * </p>
-     *
-     * @param wrapper
-     * @return
-     */
-
-    public List<T> selectList(Wrapper wrapper) {
-        Map<String, Object> map = new HashMap<>();
-        map.put("ew", wrapper);
-        return sqlSession().selectList(sqlStatement(SqlMethod.SELECT_LIST), map);
-    }
-
-    /**
-     * <p>
-     * 查询所有
-     * </p>
-     *
-     * @param whereClause
-     * @param args
-     * @return
-     */
-    public List<T> selectList(String whereClause, Object... args) {
-        return selectList(Condition.create().where(whereClause, args));
-    }
-
-    /**
-     * <p>
-     * 查询一条记录
-     * </p>
-     *
-     * @param wrapper
-     * @return
-     */
-    public T selectOne(Wrapper wrapper) {
-        return SqlHelper.getObject(selectList(wrapper));
-    }
-
-    /**
-     * <p>
-     * 查询一条记录
-     * </p>
-     *
-     * @param whereClause
-     * @param args
-     * @return
-     */
-    public T selectOne(String whereClause, Object... args) {
-        return selectOne(Condition.create().where(whereClause, args));
-    }
-
-    /**
-     * <p>
-     * 翻页查询
-     * </p>
-     *
-     * @param page    翻页查询条件
-     * @param wrapper
-     * @return
-     */
-    public Page<T> selectPage(Page<T> page, Wrapper<T> wrapper) {
-        Map<String, Object> map = new HashMap<>();
-        SqlHelper.fillWrapper(page, wrapper);
-        map.put("ew", wrapper);
-        List<T> tl = sqlSession().selectList(sqlStatement(SqlMethod.SELECT_PAGE), map, page);
-        page.setRecords(tl);
-        return page;
-    }
-
-    /**
-     * <p>
-     * 查询所有(分页)
-     * </p>
-     *
-     * @param page
-     * @param whereClause
-     * @param args
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    public Page<T> selectPage(Page<T> page, String whereClause, Object... args) {
-        return selectPage(page, Condition.create().where(whereClause, args));
-    }
-
-    /**
-     * <p>
-     * 查询总数
-     * </p>
-     *
-     * @param whereClause 查询条件
-     * @param args        查询条件值
-     * @return
-     */
-    public int selectCount(String whereClause, Object... args) {
-        return selectCount(Condition.create().where(whereClause, args));
-    }
-
-    /**
-     * <p>
-     * 查询总数
-     * </p>
-     *
-     * @param wrapper
-     * @return
-     */
-    public int selectCount(Wrapper wrapper) {
-        Map<String, Object> map = new HashMap<>();
-        map.put("ew", wrapper);
-        return SqlHelper.retCount(sqlSession().<Integer>selectOne(sqlStatement(SqlMethod.SELECT_COUNT), map));
-    }
-
-    /**
-     * <p>
-     * 执行 SQL
-     * </p>
-     */
-    public SqlRunner sql() {
-        return new SqlRunner(getClass());
-    }
-
-    /**
-     * <p>
-     * 获取Session 默认自动提交
-     * <p/>
-     */
-    protected SqlSession sqlSession() {
-        return SqlHelper.sqlSession(getClass());
-    }
-
-    /**
-     * 获取SqlStatement
-     *
-     * @param sqlMethod
-     * @return
-     */
-    protected String sqlStatement(SqlMethod sqlMethod) {
-        return sqlStatement(sqlMethod.getMethod());
-    }
-
-    /**
-     * 获取SqlStatement
-     *
-     * @param sqlMethod
-     * @return
-     */
-    protected String sqlStatement(String sqlMethod) {
-        return SqlHelper.table(getClass()).getSqlStatement(sqlMethod);
-    }
-
-    /**
-     * 主键值
-     */
-    protected abstract Serializable pkVal();
-
-}
+/**
+ * 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.activerecord;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.session.SqlSession;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.baomidou.mybatisplus.enums.SqlMethod;
+import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.mapper.Condition;
+import com.baomidou.mybatisplus.mapper.SqlHelper;
+import com.baomidou.mybatisplus.mapper.SqlRunner;
+import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.baomidou.mybatisplus.plugins.Page;
+import com.baomidou.mybatisplus.toolkit.StringUtils;
+
+/**
+ * <p>
+ * ActiveRecord 模式 CRUD
+ * </p>
+ *
+ * @param <T>
+ * @author hubin
+ * @Date 2016-11-06
+ */
+@SuppressWarnings({"rawtypes"})
+public abstract class Model<T extends Model> implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * <p>
+     * 插入(字段选择插入)
+     * </p>
+     */
+    @Transactional
+    public boolean insert() {
+        return SqlHelper.retBool(sqlSession().insert(sqlStatement(SqlMethod.INSERT_ONE), this));
+    }
+
+    /**
+     * <p>
+     * 插入(所有字段插入)
+     * </p>
+     */
+    @Transactional
+    public boolean insertAllColumn() {
+        return SqlHelper.retBool(sqlSession().insert(sqlStatement(SqlMethod.INSERT_ONE_ALL_COLUMN), this));
+    }
+
+    /**
+     * <p>
+     * 插入 OR 更新
+     * </p>
+     */
+    @Transactional
+    public boolean insertOrUpdate() {
+        if (StringUtils.checkValNull(pkVal())) {
+            // insert
+            return insert();
+        } else {
+            /*
+             * 更新成功直接返回,失败执行插入逻辑
+			 */
+            return updateById() || insert();
+        }
+    }
+
+    /**
+     * <p>
+     * 根据 ID 删除
+     * </p>
+     *
+     * @param id 主键ID
+     * @return
+     */
+    @Transactional
+    public boolean deleteById(Serializable id) {
+        return SqlHelper.retBool(sqlSession().delete(sqlStatement(SqlMethod.DELETE_BY_ID), id));
+    }
+
+    /**
+     * <p>
+     * 根据主键删除
+     * </p>
+     *
+     * @return
+     */
+    @Transactional
+    public boolean deleteById() {
+        if (StringUtils.checkValNull(pkVal())) {
+            throw new MybatisPlusException("deleteById primaryKey is null.");
+        }
+        return deleteById(this.pkVal());
+    }
+
+    /**
+     * <p>
+     * 删除记录
+     * </p>
+     *
+     * @param whereClause 查询条件
+     * @param args        查询条件值
+     * @return
+     */
+    @Transactional
+    public boolean delete(String whereClause, Object... args) {
+        return delete(Condition.create().where(whereClause, args));
+    }
+
+    /**
+     * <p>
+     * 删除记录
+     * </p>
+     *
+     * @param wrapper
+     * @return
+     */
+    @Transactional
+    public boolean delete(Wrapper wrapper) {
+        Map<String, Object> map = new HashMap<>();
+        // delete
+        map.put("ew", wrapper);
+        return SqlHelper.retBool(sqlSession().delete(sqlStatement(SqlMethod.DELETE), map));
+    }
+
+    /**
+     * <p>
+     * 更新(字段选择更新)
+     * </p>
+     */
+    @Transactional
+    public boolean updateById() {
+        if (StringUtils.checkValNull(pkVal())) {
+            throw new MybatisPlusException("updateById primaryKey is null.");
+        }
+        // updateById
+        return SqlHelper.retBool(sqlSession().update(sqlStatement(SqlMethod.UPDATE_BY_ID), this));
+    }
+
+    /**
+     * <p>
+     * 更新(所有字段更新)
+     * </p>
+     */
+    @Transactional
+    public boolean updateAllColumnById() {
+        if (StringUtils.checkValNull(pkVal())) {
+            throw new MybatisPlusException("updateAllColumnById primaryKey is null.");
+        }
+        // updateById
+        return SqlHelper.retBool(sqlSession().update(sqlStatement(SqlMethod.UPDATE_ALL_COLUMN_BY_ID), this));
+    }
+
+    /**
+     * <p>
+     * 执行 SQL 更新
+     * </p>
+     *
+     * @param whereClause 查询条件
+     * @param args        查询条件值
+     * @return
+     */
+    @Transactional
+    public boolean update(String whereClause, Object... args) {
+        // update
+        return update(Condition.create().where(whereClause, args));
+    }
+
+    /**
+     * <p>
+     * 执行 SQL 更新
+     * </p>
+     *
+     * @param wrapper
+     * @return
+     */
+    @Transactional
+    public boolean update(Wrapper wrapper) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("et", this);
+        map.put("ew", wrapper);
+        // update
+        return SqlHelper.retBool(sqlSession().update(sqlStatement(SqlMethod.UPDATE), map));
+    }
+
+    /**
+     * <p>
+     * 查询所有
+     * </p>
+     *
+     * @return
+     */
+    public List<T> selectAll() {
+        return sqlSession().selectList(sqlStatement(SqlMethod.SELECT_LIST));
+    }
+
+    /**
+     * <p>
+     * 根据 ID 查询
+     * </p>
+     *
+     * @param id 主键ID
+     * @return
+     */
+    public T selectById(Serializable id) {
+        return sqlSession().selectOne(sqlStatement(SqlMethod.SELECT_BY_ID), id);
+    }
+
+    /**
+     * <p>
+     * 根据主键查询
+     * </p>
+     *
+     * @return
+     */
+    public T selectById() {
+        if (StringUtils.checkValNull(pkVal())) {
+            throw new MybatisPlusException("selectById primaryKey is null.");
+        }
+        return selectById(this.pkVal());
+    }
+
+    /**
+     * <p>
+     * 查询总记录数
+     * </p>
+     *
+     * @param wrapper
+     * @return
+     */
+
+    public List<T> selectList(Wrapper wrapper) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("ew", wrapper);
+        return sqlSession().selectList(sqlStatement(SqlMethod.SELECT_LIST), map);
+    }
+
+    /**
+     * <p>
+     * 查询所有
+     * </p>
+     *
+     * @param whereClause
+     * @param args
+     * @return
+     */
+    public List<T> selectList(String whereClause, Object... args) {
+        return selectList(Condition.create().where(whereClause, args));
+    }
+
+    /**
+     * <p>
+     * 查询一条记录
+     * </p>
+     *
+     * @param wrapper
+     * @return
+     */
+    public T selectOne(Wrapper wrapper) {
+        return SqlHelper.getObject(selectList(wrapper));
+    }
+
+    /**
+     * <p>
+     * 查询一条记录
+     * </p>
+     *
+     * @param whereClause
+     * @param args
+     * @return
+     */
+    public T selectOne(String whereClause, Object... args) {
+        return selectOne(Condition.create().where(whereClause, args));
+    }
+
+    /**
+     * <p>
+     * 翻页查询
+     * </p>
+     *
+     * @param page    翻页查询条件
+     * @param wrapper
+     * @return
+     */
+    public Page<T> selectPage(Page<T> page, Wrapper<T> wrapper) {
+        Map<String, Object> map = new HashMap<>();
+        SqlHelper.fillWrapper(page, wrapper);
+        map.put("ew", wrapper);
+        List<T> tl = sqlSession().selectList(sqlStatement(SqlMethod.SELECT_PAGE), map, page);
+        page.setRecords(tl);
+        return page;
+    }
+
+    /**
+     * <p>
+     * 查询所有(分页)
+     * </p>
+     *
+     * @param page
+     * @param whereClause
+     * @param args
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public Page<T> selectPage(Page<T> page, String whereClause, Object... args) {
+        return selectPage(page, Condition.create().where(whereClause, args));
+    }
+
+    /**
+     * <p>
+     * 查询总数
+     * </p>
+     *
+     * @param whereClause 查询条件
+     * @param args        查询条件值
+     * @return
+     */
+    public int selectCount(String whereClause, Object... args) {
+        return selectCount(Condition.create().where(whereClause, args));
+    }
+
+    /**
+     * <p>
+     * 查询总数
+     * </p>
+     *
+     * @param wrapper
+     * @return
+     */
+    public int selectCount(Wrapper wrapper) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("ew", wrapper);
+        return SqlHelper.retCount(sqlSession().<Integer>selectOne(sqlStatement(SqlMethod.SELECT_COUNT), map));
+    }
+
+    /**
+     * <p>
+     * 执行 SQL
+     * </p>
+     */
+    public SqlRunner sql() {
+        return new SqlRunner(getClass());
+    }
+
+    /**
+     * <p>
+     * 获取Session 默认自动提交
+     * <p/>
+     */
+    protected SqlSession sqlSession() {
+        return SqlHelper.sqlSession(getClass());
+    }
+
+    /**
+     * 获取SqlStatement
+     *
+     * @param sqlMethod
+     * @return
+     */
+    protected String sqlStatement(SqlMethod sqlMethod) {
+        return sqlStatement(sqlMethod.getMethod());
+    }
+
+    /**
+     * 获取SqlStatement
+     *
+     * @param sqlMethod
+     * @return
+     */
+    protected String sqlStatement(String sqlMethod) {
+        return SqlHelper.table(getClass()).getSqlStatement(sqlMethod);
+    }
+
+    /**
+     * 主键值
+     */
+    protected abstract Serializable pkVal();
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/activerecord/package-info.java → src/main/java/com/baomidou/mybatisplus/activerecord/package-info.java


+ 52 - 52
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/KeySequence.java → src/main/java/com/baomidou/mybatisplus/annotations/KeySequence.java

@@ -1,52 +1,52 @@
-/**
- * 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.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <p>
- * 序列主键策略
- * oracle
- * </p>
- *
- * @author zashitou
- * @since 2017.4.20
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-@Inherited
-public @interface KeySequence {
-
-    /*
-     * <p>
-     * 序列名
-     * </p>
-     */
-    String value() default "";
-
-    /*
-     * <p>
-     * id的类型
-     * </p>
-     */
-    Class idClazz() default Long.class;
-
-}
+/**
+ * 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p>
+ * 序列主键策略
+ * oracle
+ * </p>
+ *
+ * @author zashitou
+ * @since 2017.4.20
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Inherited
+public @interface KeySequence {
+
+    /*
+     * <p>
+     * 序列名
+     * </p>
+     */
+    String value() default "";
+
+    /*
+     * <p>
+     * id的类型
+     * </p>
+     */
+    Class idClazz() default Long.class;
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/TableField.java → src/main/java/com/baomidou/mybatisplus/annotations/TableField.java


+ 52 - 52
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/TableId.java → src/main/java/com/baomidou/mybatisplus/annotations/TableId.java

@@ -1,52 +1,52 @@
-/**
- * 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.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import com.baomidou.mybatisplus.enums.IdType;
-
-/**
- * <p>
- * 表主键标识
- * </p>
- *
- * @author hubin
- * @since 2016-01-23
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface TableId {
-
-    /*
-     * <p>
-     * 字段值(驼峰命名方式,该值可无)
-     * </p>
-     */
-    String value() default "";
-
-    /*
-     * <p>
-     * 主键ID
-     * </p>
-     * {@link IdType}
-     */
-    IdType type() default IdType.NONE;
-
-}
+/**
+ * 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.baomidou.mybatisplus.enums.IdType;
+
+/**
+ * <p>
+ * 表主键标识
+ * </p>
+ *
+ * @author hubin
+ * @since 2016-01-23
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface TableId {
+
+    /*
+     * <p>
+     * 字段值(驼峰命名方式,该值可无)
+     * </p>
+     */
+    String value() default "";
+
+    /*
+     * <p>
+     * 主键ID
+     * </p>
+     * {@link IdType}
+     */
+    IdType type() default IdType.NONE;
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/TableLogic.java → src/main/java/com/baomidou/mybatisplus/annotations/TableLogic.java


+ 49 - 49
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/TableName.java → src/main/java/com/baomidou/mybatisplus/annotations/TableName.java

@@ -1,49 +1,49 @@
-/**
- * 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.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <p>
- * 数据库表相关
- * </p>
- *
- * @author hubin
- * @since 2016-01-23
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface TableName {
-
-    /*
-     * <p>
-     * 实体对应的表名
-     * </p>
-     */
-    String value() default "";
-
-    /*
-     * <p>
-     * 实体映射结果集
-     * </p>
-     */
-    String resultMap() default "";
-
-}
+/**
+ * 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p>
+ * 数据库表相关
+ * </p>
+ *
+ * @author hubin
+ * @since 2016-01-23
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface TableName {
+
+    /*
+     * <p>
+     * 实体对应的表名
+     * </p>
+     */
+    String value() default "";
+
+    /*
+     * <p>
+     * 实体映射结果集
+     * </p>
+     */
+    String resultMap() default "";
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/Version.java → src/main/java/com/baomidou/mybatisplus/annotations/Version.java


+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/package-info.java → src/main/java/com/baomidou/mybatisplus/annotations/package-info.java

@@ -1,4 +1,4 @@
-/**
- * 注解方法类
- */
-package com.baomidou.mybatisplus.annotations;
+/**
+ * 注解方法类
+ */
+package com.baomidou.mybatisplus.annotations;

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/Column.java → src/main/java/com/baomidou/mybatisplus/entity/Column.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/CountOptimize.java → src/main/java/com/baomidou/mybatisplus/entity/CountOptimize.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/DefaultMetaObjectHandler.java → src/main/java/com/baomidou/mybatisplus/entity/DefaultMetaObjectHandler.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/GlobalConfiguration.java → src/main/java/com/baomidou/mybatisplus/entity/GlobalConfiguration.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/OracleKeyGenerator.java → src/main/java/com/baomidou/mybatisplus/entity/OracleKeyGenerator.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/TableFieldInfo.java → src/main/java/com/baomidou/mybatisplus/entity/TableFieldInfo.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/TableInfo.java → src/main/java/com/baomidou/mybatisplus/entity/TableInfo.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/entity/package-info.java → src/main/java/com/baomidou/mybatisplus/entity/package-info.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/DBType.java → src/main/java/com/baomidou/mybatisplus/enums/DBType.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/FieldStrategy.java → src/main/java/com/baomidou/mybatisplus/enums/FieldStrategy.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/IdType.java → src/main/java/com/baomidou/mybatisplus/enums/IdType.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/Optimize.java → src/main/java/com/baomidou/mybatisplus/enums/Optimize.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/SqlLike.java → src/main/java/com/baomidou/mybatisplus/enums/SqlLike.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/SqlMethod.java → src/main/java/com/baomidou/mybatisplus/enums/SqlMethod.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/enums/package-info.java → src/main/java/com/baomidou/mybatisplus/enums/package-info.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/exceptions/MybatisPlusException.java → src/main/java/com/baomidou/mybatisplus/exceptions/MybatisPlusException.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/exceptions/package-info.java → src/main/java/com/baomidou/mybatisplus/exceptions/package-info.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/AbstractGenerator.java → src/main/java/com/baomidou/mybatisplus/generator/AbstractGenerator.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java → src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/InjectionConfig.java → src/main/java/com/baomidou/mybatisplus/generator/InjectionConfig.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/ConstVal.java → src/main/java/com/baomidou/mybatisplus/generator/config/ConstVal.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java → src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/FileOutConfig.java → src/main/java/com/baomidou/mybatisplus/generator/config/FileOutConfig.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/GlobalConfig.java → src/main/java/com/baomidou/mybatisplus/generator/config/GlobalConfig.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/ITypeConvert.java → src/main/java/com/baomidou/mybatisplus/generator/config/ITypeConvert.java


+ 138 - 138
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/PackageConfig.java → src/main/java/com/baomidou/mybatisplus/generator/config/PackageConfig.java

@@ -1,138 +1,138 @@
-/**
- * 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.generator.config;
-
-import com.baomidou.mybatisplus.toolkit.StringUtils;
-
-/**
- * <p>
- * 跟包相关的配置项
- *
- * @author YangHu, tangguo
- * @since 2016-08-30
- */
-public class PackageConfig {
-
-    /**
-     * 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
-     */
-    private String parent = "com.baomidou";
-
-    /**
-     * 父包模块名。
-     */
-    private String moduleName = null;
-
-    /**
-     * Entity包名
-     */
-    private String entity = "entity";
-
-    /**
-     * Service包名
-     */
-    private String service = "service";
-
-    /**
-     * Service Impl包名
-     */
-    private String serviceImpl = "service.impl";
-    /**
-     * Mapper包名
-     */
-    private String mapper = "mapper";
-
-    /**
-     * Mapper XML包名
-     */
-    private String xml = "mapper.xml";
-
-    /**
-     * Controller包名
-     */
-    private String controller = "web";
-
-    public String getParent() {
-        if (StringUtils.isNotEmpty(moduleName)) {
-            return parent + "." + moduleName;
-        }
-        return parent;
-    }
-
-    public void setParent(String parent) {
-        this.parent = parent;
-    }
-
-    public String getModuleName() {
-        return moduleName;
-    }
-
-    public void setModuleName(String moduleName) {
-        this.moduleName = moduleName;
-    }
-
-    public String getEntity() {
-        return entity;
-    }
-
-    public void setEntity(String entity) {
-        this.entity = entity;
-    }
-
-    public String getService() {
-        return service;
-    }
-
-    public void setService(String service) {
-        this.service = service;
-    }
-
-    public String getServiceImpl() {
-        return serviceImpl;
-    }
-
-    public void setServiceImpl(String serviceImpl) {
-        this.serviceImpl = serviceImpl;
-    }
-
-    public String getMapper() {
-        return mapper;
-    }
-
-    public void setMapper(String mapper) {
-        this.mapper = mapper;
-    }
-
-    public String getXml() {
-        return xml;
-    }
-
-    public void setXml(String xml) {
-        this.xml = xml;
-    }
-
-    public String getController() {
-        if (StringUtils.isEmpty(controller)) {
-            return "web";
-        }
-        return controller;
-    }
-
-    public void setController(String controller) {
-        this.controller = controller;
-    }
-
-}
+/**
+ * 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.generator.config;
+
+import com.baomidou.mybatisplus.toolkit.StringUtils;
+
+/**
+ * <p>
+ * 跟包相关的配置项
+ *
+ * @author YangHu, tangguo
+ * @since 2016-08-30
+ */
+public class PackageConfig {
+
+    /**
+     * 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
+     */
+    private String parent = "com.baomidou";
+
+    /**
+     * 父包模块名。
+     */
+    private String moduleName = null;
+
+    /**
+     * Entity包名
+     */
+    private String entity = "entity";
+
+    /**
+     * Service包名
+     */
+    private String service = "service";
+
+    /**
+     * Service Impl包名
+     */
+    private String serviceImpl = "service.impl";
+    /**
+     * Mapper包名
+     */
+    private String mapper = "mapper";
+
+    /**
+     * Mapper XML包名
+     */
+    private String xml = "mapper.xml";
+
+    /**
+     * Controller包名
+     */
+    private String controller = "web";
+
+    public String getParent() {
+        if (StringUtils.isNotEmpty(moduleName)) {
+            return parent + "." + moduleName;
+        }
+        return parent;
+    }
+
+    public void setParent(String parent) {
+        this.parent = parent;
+    }
+
+    public String getModuleName() {
+        return moduleName;
+    }
+
+    public void setModuleName(String moduleName) {
+        this.moduleName = moduleName;
+    }
+
+    public String getEntity() {
+        return entity;
+    }
+
+    public void setEntity(String entity) {
+        this.entity = entity;
+    }
+
+    public String getService() {
+        return service;
+    }
+
+    public void setService(String service) {
+        this.service = service;
+    }
+
+    public String getServiceImpl() {
+        return serviceImpl;
+    }
+
+    public void setServiceImpl(String serviceImpl) {
+        this.serviceImpl = serviceImpl;
+    }
+
+    public String getMapper() {
+        return mapper;
+    }
+
+    public void setMapper(String mapper) {
+        this.mapper = mapper;
+    }
+
+    public String getXml() {
+        return xml;
+    }
+
+    public void setXml(String xml) {
+        this.xml = xml;
+    }
+
+    public String getController() {
+        if (StringUtils.isEmpty(controller)) {
+            return "web";
+        }
+        return controller;
+    }
+
+    public void setController(String controller) {
+        this.controller = controller;
+    }
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java → src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java


+ 88 - 88
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/TemplateConfig.java → src/main/java/com/baomidou/mybatisplus/generator/config/TemplateConfig.java

@@ -1,88 +1,88 @@
-/**
- * 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.generator.config;
-
-/**
- * <p>
- * 模板路径配置项
- * </p>
- *
- * @author tzg
- * @since 2016/11/10
- */
-public class TemplateConfig {
-
-    private String entity = ConstVal.TEMPLATE_ENTITY;
-
-    private String service = ConstVal.TEMPLATE_SERVICE;
-
-    private String serviceImpl = ConstVal.TEMPLATE_SERVICEIMPL;
-
-    private String mapper = ConstVal.TEMPLATE_MAPPER;
-
-    private String xml = ConstVal.TEMPLATE_XML;
-
-    private String controller = ConstVal.TEMPLATE_CONTROLLER;
-
-    public String getEntity() {
-        return entity;
-    }
-
-    public void setEntity(String entity) {
-        this.entity = entity;
-    }
-
-    public String getService() {
-        return service;
-    }
-
-    public void setService(String service) {
-        this.service = service;
-    }
-
-    public String getServiceImpl() {
-        return serviceImpl;
-    }
-
-    public void setServiceImpl(String serviceImpl) {
-        this.serviceImpl = serviceImpl;
-    }
-
-    public String getMapper() {
-        return mapper;
-    }
-
-    public void setMapper(String mapper) {
-        this.mapper = mapper;
-    }
-
-    public String getXml() {
-        return xml;
-    }
-
-    public void setXml(String xml) {
-        this.xml = xml;
-    }
-
-    public String getController() {
-        return controller;
-    }
-
-    public void setController(String controller) {
-        this.controller = controller;
-    }
-
-}
+/**
+ * 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.generator.config;
+
+/**
+ * <p>
+ * 模板路径配置项
+ * </p>
+ *
+ * @author tzg
+ * @since 2016/11/10
+ */
+public class TemplateConfig {
+
+    private String entity = ConstVal.TEMPLATE_ENTITY;
+
+    private String service = ConstVal.TEMPLATE_SERVICE;
+
+    private String serviceImpl = ConstVal.TEMPLATE_SERVICEIMPL;
+
+    private String mapper = ConstVal.TEMPLATE_MAPPER;
+
+    private String xml = ConstVal.TEMPLATE_XML;
+
+    private String controller = ConstVal.TEMPLATE_CONTROLLER;
+
+    public String getEntity() {
+        return entity;
+    }
+
+    public void setEntity(String entity) {
+        this.entity = entity;
+    }
+
+    public String getService() {
+        return service;
+    }
+
+    public void setService(String service) {
+        this.service = service;
+    }
+
+    public String getServiceImpl() {
+        return serviceImpl;
+    }
+
+    public void setServiceImpl(String serviceImpl) {
+        this.serviceImpl = serviceImpl;
+    }
+
+    public String getMapper() {
+        return mapper;
+    }
+
+    public void setMapper(String mapper) {
+        this.mapper = mapper;
+    }
+
+    public String getXml() {
+        return xml;
+    }
+
+    public void setXml(String xml) {
+        this.xml = xml;
+    }
+
+    public String getController() {
+        return controller;
+    }
+
+    public void setController(String controller) {
+        this.controller = controller;
+    }
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java → src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java


+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/builder/package-info.java → src/main/java/com/baomidou/mybatisplus/generator/config/builder/package-info.java

@@ -1,4 +1,4 @@
-/**
- * 代码生成器,构建类
- */
-package com.baomidou.mybatisplus.generator.config.builder;
+/**
+ * 代码生成器,构建类
+ */
+package com.baomidou.mybatisplus.generator.config.builder;

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/converts/MySqlTypeConvert.java → src/main/java/com/baomidou/mybatisplus/generator/config/converts/MySqlTypeConvert.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/converts/OracleTypeConvert.java → src/main/java/com/baomidou/mybatisplus/generator/config/converts/OracleTypeConvert.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/converts/PostgreSqlTypeConvert.java → src/main/java/com/baomidou/mybatisplus/generator/config/converts/PostgreSqlTypeConvert.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/converts/SqlServerTypeConvert.java → src/main/java/com/baomidou/mybatisplus/generator/config/converts/SqlServerTypeConvert.java


+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/package-info.java → src/main/java/com/baomidou/mybatisplus/generator/config/package-info.java

@@ -1,4 +1,4 @@
-/**
- * 代码生成器,配置相关类
- */
-package com.baomidou.mybatisplus.generator.config;
+/**
+ * 代码生成器,配置相关类
+ */
+package com.baomidou.mybatisplus.generator.config;

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableField.java → src/main/java/com/baomidou/mybatisplus/generator/config/po/TableField.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java → src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java


+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/po/package-info.java → src/main/java/com/baomidou/mybatisplus/generator/config/po/package-info.java

@@ -1,4 +1,4 @@
-/**
- * 代码生成器,输出相关类
- */
-package com.baomidou.mybatisplus.generator.config.po;
+/**
+ * 代码生成器,输出相关类
+ */
+package com.baomidou.mybatisplus.generator.config.po;

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/rules/DbColumnType.java → src/main/java/com/baomidou/mybatisplus/generator/config/rules/DbColumnType.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/rules/DbType.java → src/main/java/com/baomidou/mybatisplus/generator/config/rules/DbType.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategy.java → src/main/java/com/baomidou/mybatisplus/generator/config/rules/NamingStrategy.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/rules/QuerySQL.java → src/main/java/com/baomidou/mybatisplus/generator/config/rules/QuerySQL.java


+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/config/rules/package-info.java → src/main/java/com/baomidou/mybatisplus/generator/config/rules/package-info.java

@@ -1,4 +1,4 @@
-/**
- * 代码生成器,规则相关类
- */
-package com.baomidou.mybatisplus.generator.config.rules;
+/**
+ * 代码生成器,规则相关类
+ */
+package com.baomidou.mybatisplus.generator.config.rules;

+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/package-info.java → src/main/java/com/baomidou/mybatisplus/generator/package-info.java

@@ -1,4 +1,4 @@
-/**
- * 代码生成器相关类
- */
-package com.baomidou.mybatisplus.generator;
+/**
+ * 代码生成器相关类
+ */
+package com.baomidou.mybatisplus.generator;

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java → src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java


+ 253 - 253
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/BaseMapper.java → src/main/java/com/baomidou/mybatisplus/mapper/BaseMapper.java

@@ -1,253 +1,253 @@
-/**
- * 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.mapper;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.RowBounds;
-
-/**
- * <p>
- * Mapper 继承该接口后,无需编写 mapper.xml 文件,即可获得CRUD功能
- * </p>
- * <p>
- * 这个 Mapper 支持 id 泛型
- * </p>
- *
- * @author hubin
- * @Date 2016-01-23
- */
-public interface BaseMapper<T> {
-
-    /**
-     * <p>
-     * 插入一条记录
-     * </p>
-     *
-     * @param entity
-     *            实体对象
-     * @return int
-     */
-    Integer insert(T entity);
-
-    /**
-     * <p>
-     * 插入一条记录
-     * </p>
-     *
-     * @param entity
-     *            实体对象
-     * @return int
-     */
-    Integer insertAllColumn(T entity);
-
-    /**
-     * <p>
-     * 根据 ID 删除
-     * </p>
-     *
-     * @param id
-     *            主键ID
-     * @return int
-     */
-    Integer deleteById(Serializable id);
-
-    /**
-     * <p>
-     * 根据 columnMap 条件,删除记录
-     * </p>
-     *
-     * @param columnMap
-     *            表字段 map 对象
-     * @return int
-     */
-    Integer deleteByMap(@Param("cm") Map<String, Object> columnMap);
-
-    /**
-     * <p>
-     * 根据 entity 条件,删除记录
-     * </p>
-     *
-     * @param wrapper
-     *            实体对象封装操作类(可以为 null)
-     * @return int
-     */
-    Integer delete(@Param("ew") Wrapper<T> wrapper);
-
-    /**
-     * <p>
-     * 删除(根据ID 批量删除)
-     * </p>
-     *
-     * @param idList
-     *            主键ID列表
-     * @return int
-     */
-    Integer deleteBatchIds(List<? extends Serializable> idList);
-
-    /**
-     * <p>
-     * 根据 ID 修改
-     * </p>
-     *
-     * @param entity
-     *            实体对象
-     * @return int
-     */
-    Integer updateById(@Param("et") T entity);
-
-    /**
-     * <p>
-     * 根据 ID 修改
-     * </p>
-     *
-     * @param entity
-     *            实体对象
-     * @return int
-     */
-    Integer updateAllColumnById(@Param("et") T entity);
-
-    /**
-     * <p>
-     * 根据 whereEntity 条件,更新记录
-     * </p>
-     *
-     * @param entity
-     *            实体对象
-     * @param wrapper
-     *            实体对象封装操作类(可以为 null)
-     * @return
-     */
-    Integer update(@Param("et") T entity, @Param("ew") Wrapper<T> wrapper);
-
-    /**
-     * <p>
-     * 根据 ID 查询
-     * </p>
-     *
-     * @param id
-     *            主键ID
-     * @return T
-     */
-    T selectById(Serializable id);
-
-    /**
-     * <p>
-     * 查询(根据ID 批量查询)
-     * </p>
-     *
-     * @param idList
-     *            主键ID列表
-     * @return List<T>
-     */
-    List<T> selectBatchIds(List<? extends Serializable> idList);
-
-    /**
-     * <p>
-     * 查询(根据 columnMap 条件)
-     * </p>
-     *
-     * @param columnMap
-     *            表字段 map 对象
-     * @return List<T>
-     */
-    List<T> selectByMap(@Param("cm") Map<String, Object> columnMap);
-
-    /**
-     * <p>
-     * 根据 entity 条件,查询一条记录
-     * </p>
-     *
-     * @param entity
-     *            实体对象
-     * @return T
-     */
-    T selectOne(@Param("ew") T entity);
-
-    /**
-     * <p>
-     * 根据 Wrapper 条件,查询总记录数
-     * </p>
-     *
-     * @param wrapper
-     *            实体对象
-     * @return int
-     */
-    Integer selectCount(@Param("ew") Wrapper<T> wrapper);
-
-    /**
-     * <p>
-     * 根据 entity 条件,查询全部记录
-     * </p>
-     *
-     * @param wrapper
-     *            实体对象封装操作类(可以为 null)
-     * @return List<T>
-     */
-    List<T> selectList(@Param("ew") Wrapper<T> wrapper);
-
-    /**
-     * <p>
-     * 根据 Wrapper 条件,查询全部记录
-     * </p>
-     *
-     * @param wrapper
-     *            实体对象封装操作类(可以为 null)
-     * @return List<T>
-     */
-    List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> wrapper);
-
-    /**
-     * <p>
-     * 根据 Wrapper 条件,查询全部记录
-     * </p>
-     *
-     * @param wrapper
-     *            实体对象封装操作类(可以为 null)
-     * @return List<Object>
-     */
-    List<Object> selectObjs(@Param("ew") Wrapper<T> wrapper);
-
-    /**
-     * <p>
-     * 根据 entity 条件,查询全部记录(并翻页)
-     * </p>
-     *
-     * @param rowBounds
-     *            分页查询条件(可以为 RowBounds.DEFAULT)
-     * @param wrapper
-     *            实体对象封装操作类(可以为 null)
-     * @return List<T>
-     */
-    List<T> selectPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
-
-    /**
-     * <p>
-     * 根据 Wrapper 条件,查询全部记录(并翻页)
-     * </p>
-     *
-     * @param rowBounds
-     *            分页查询条件(可以为 RowBounds.DEFAULT)
-     * @param wrapper
-     *            实体对象封装操作类
-     * @return List<Map<String, Object>>
-     */
-    List<Map<String, Object>> selectMapsPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
-
-}
+/**
+ * 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.mapper;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.RowBounds;
+
+/**
+ * <p>
+ * Mapper 继承该接口后,无需编写 mapper.xml 文件,即可获得CRUD功能
+ * </p>
+ * <p>
+ * 这个 Mapper 支持 id 泛型
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-01-23
+ */
+public interface BaseMapper<T> {
+
+    /**
+     * <p>
+     * 插入一条记录
+     * </p>
+     *
+     * @param entity
+     *            实体对象
+     * @return int
+     */
+    Integer insert(T entity);
+
+    /**
+     * <p>
+     * 插入一条记录
+     * </p>
+     *
+     * @param entity
+     *            实体对象
+     * @return int
+     */
+    Integer insertAllColumn(T entity);
+
+    /**
+     * <p>
+     * 根据 ID 删除
+     * </p>
+     *
+     * @param id
+     *            主键ID
+     * @return int
+     */
+    Integer deleteById(Serializable id);
+
+    /**
+     * <p>
+     * 根据 columnMap 条件,删除记录
+     * </p>
+     *
+     * @param columnMap
+     *            表字段 map 对象
+     * @return int
+     */
+    Integer deleteByMap(@Param("cm") Map<String, Object> columnMap);
+
+    /**
+     * <p>
+     * 根据 entity 条件,删除记录
+     * </p>
+     *
+     * @param wrapper
+     *            实体对象封装操作类(可以为 null)
+     * @return int
+     */
+    Integer delete(@Param("ew") Wrapper<T> wrapper);
+
+    /**
+     * <p>
+     * 删除(根据ID 批量删除)
+     * </p>
+     *
+     * @param idList
+     *            主键ID列表
+     * @return int
+     */
+    Integer deleteBatchIds(List<? extends Serializable> idList);
+
+    /**
+     * <p>
+     * 根据 ID 修改
+     * </p>
+     *
+     * @param entity
+     *            实体对象
+     * @return int
+     */
+    Integer updateById(@Param("et") T entity);
+
+    /**
+     * <p>
+     * 根据 ID 修改
+     * </p>
+     *
+     * @param entity
+     *            实体对象
+     * @return int
+     */
+    Integer updateAllColumnById(@Param("et") T entity);
+
+    /**
+     * <p>
+     * 根据 whereEntity 条件,更新记录
+     * </p>
+     *
+     * @param entity
+     *            实体对象
+     * @param wrapper
+     *            实体对象封装操作类(可以为 null)
+     * @return
+     */
+    Integer update(@Param("et") T entity, @Param("ew") Wrapper<T> wrapper);
+
+    /**
+     * <p>
+     * 根据 ID 查询
+     * </p>
+     *
+     * @param id
+     *            主键ID
+     * @return T
+     */
+    T selectById(Serializable id);
+
+    /**
+     * <p>
+     * 查询(根据ID 批量查询)
+     * </p>
+     *
+     * @param idList
+     *            主键ID列表
+     * @return List<T>
+     */
+    List<T> selectBatchIds(List<? extends Serializable> idList);
+
+    /**
+     * <p>
+     * 查询(根据 columnMap 条件)
+     * </p>
+     *
+     * @param columnMap
+     *            表字段 map 对象
+     * @return List<T>
+     */
+    List<T> selectByMap(@Param("cm") Map<String, Object> columnMap);
+
+    /**
+     * <p>
+     * 根据 entity 条件,查询一条记录
+     * </p>
+     *
+     * @param entity
+     *            实体对象
+     * @return T
+     */
+    T selectOne(@Param("ew") T entity);
+
+    /**
+     * <p>
+     * 根据 Wrapper 条件,查询总记录数
+     * </p>
+     *
+     * @param wrapper
+     *            实体对象
+     * @return int
+     */
+    Integer selectCount(@Param("ew") Wrapper<T> wrapper);
+
+    /**
+     * <p>
+     * 根据 entity 条件,查询全部记录
+     * </p>
+     *
+     * @param wrapper
+     *            实体对象封装操作类(可以为 null)
+     * @return List<T>
+     */
+    List<T> selectList(@Param("ew") Wrapper<T> wrapper);
+
+    /**
+     * <p>
+     * 根据 Wrapper 条件,查询全部记录
+     * </p>
+     *
+     * @param wrapper
+     *            实体对象封装操作类(可以为 null)
+     * @return List<T>
+     */
+    List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> wrapper);
+
+    /**
+     * <p>
+     * 根据 Wrapper 条件,查询全部记录
+     * </p>
+     *
+     * @param wrapper
+     *            实体对象封装操作类(可以为 null)
+     * @return List<Object>
+     */
+    List<Object> selectObjs(@Param("ew") Wrapper<T> wrapper);
+
+    /**
+     * <p>
+     * 根据 entity 条件,查询全部记录(并翻页)
+     * </p>
+     *
+     * @param rowBounds
+     *            分页查询条件(可以为 RowBounds.DEFAULT)
+     * @param wrapper
+     *            实体对象封装操作类(可以为 null)
+     * @return List<T>
+     */
+    List<T> selectPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
+
+    /**
+     * <p>
+     * 根据 Wrapper 条件,查询全部记录(并翻页)
+     * </p>
+     *
+     * @param rowBounds
+     *            分页查询条件(可以为 RowBounds.DEFAULT)
+     * @param wrapper
+     *            实体对象封装操作类
+     * @return List<Map<String, Object>>
+     */
+    List<Map<String, Object>> selectMapsPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
+
+}

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


+ 82 - 82
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/EntityWrapper.java → src/main/java/com/baomidou/mybatisplus/mapper/EntityWrapper.java

@@ -1,82 +1,82 @@
-/**
- * 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 com.baomidou.mybatisplus.toolkit.ReflectionKit;
-import com.baomidou.mybatisplus.toolkit.StringUtils;
-
-/**
- * <p>
- * Entity 对象封装操作类,定义T-SQL语法
- * </p>
- *
- * @author hubin , yanghu , Dyang , Caratacus
- * @Date 2016-11-7
- */
-@SuppressWarnings("serial")
-public class EntityWrapper<T> extends Wrapper<T> {
-
-    /**
-     * 数据库表映射实体类
-     */
-    protected T entity = null;
-
-    public EntityWrapper() {
-        /* 注意,传入查询参数 */
-    }
-
-    public EntityWrapper(T entity) {
-        this.entity = entity;
-    }
-
-    public EntityWrapper(T entity, String sqlSelect) {
-        this.entity = entity;
-        this.sqlSelect = sqlSelect;
-    }
-
-    public T getEntity() {
-        return entity;
-    }
-
-    public void setEntity(T entity) {
-        this.entity = entity;
-    }
-
-    /**
-     * SQL 片段
-     */
-    @Override
-    public String getSqlSegment() {
-		/*
-		 * 无条件
-		 */
-        String sqlWhere = sql.toString();
-        if (StringUtils.isEmpty(sqlWhere)) {
-            return null;
-        }
-
-		/*
-		 * 根据当前实体判断是否需要将WHERE替换成 AND 增加实体不为空但所有属性为空的情况
-		 */
-        if (isWhere != null) {
-            sqlWhere = isWhere ? sqlWhere : sqlWhere.replaceFirst("WHERE", AND_OR);
-        } else {
-            sqlWhere = ReflectionKit.checkFieldValueNotNull(entity) ? sqlWhere.replaceFirst("WHERE", AND_OR) : sqlWhere;
-        }
-        return sqlWhere;
-    }
-
-}
+/**
+ * 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 com.baomidou.mybatisplus.toolkit.ReflectionKit;
+import com.baomidou.mybatisplus.toolkit.StringUtils;
+
+/**
+ * <p>
+ * Entity 对象封装操作类,定义T-SQL语法
+ * </p>
+ *
+ * @author hubin , yanghu , Dyang , Caratacus
+ * @Date 2016-11-7
+ */
+@SuppressWarnings("serial")
+public class EntityWrapper<T> extends Wrapper<T> {
+
+    /**
+     * 数据库表映射实体类
+     */
+    protected T entity = null;
+
+    public EntityWrapper() {
+        /* 注意,传入查询参数 */
+    }
+
+    public EntityWrapper(T entity) {
+        this.entity = entity;
+    }
+
+    public EntityWrapper(T entity, String sqlSelect) {
+        this.entity = entity;
+        this.sqlSelect = sqlSelect;
+    }
+
+    public T getEntity() {
+        return entity;
+    }
+
+    public void setEntity(T entity) {
+        this.entity = entity;
+    }
+
+    /**
+     * SQL 片段
+     */
+    @Override
+    public String getSqlSegment() {
+		/*
+		 * 无条件
+		 */
+        String sqlWhere = sql.toString();
+        if (StringUtils.isEmpty(sqlWhere)) {
+            return null;
+        }
+
+		/*
+		 * 根据当前实体判断是否需要将WHERE替换成 AND 增加实体不为空但所有属性为空的情况
+		 */
+        if (isWhere != null) {
+            sqlWhere = isWhere ? sqlWhere : sqlWhere.replaceFirst("WHERE", AND_OR);
+        } else {
+            sqlWhere = ReflectionKit.checkFieldValueNotNull(entity) ? sqlWhere.replaceFirst("WHERE", AND_OR) : sqlWhere;
+        }
+        return sqlWhere;
+    }
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/IKeyGenerator.java → src/main/java/com/baomidou/mybatisplus/mapper/IKeyGenerator.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/ISqlInjector.java → src/main/java/com/baomidou/mybatisplus/mapper/ISqlInjector.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/LogicSqlInjector.java → src/main/java/com/baomidou/mybatisplus/mapper/LogicSqlInjector.java


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


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/SqlHelper.java → src/main/java/com/baomidou/mybatisplus/mapper/SqlHelper.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/SqlPlus.java → src/main/java/com/baomidou/mybatisplus/mapper/SqlPlus.java


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


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


+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/package-info.java → src/main/java/com/baomidou/mybatisplus/mapper/package-info.java

@@ -1,4 +1,4 @@
-/**
- * 自动处理 CURD 基本 SQL 相关类
- */
-package com.baomidou.mybatisplus.mapper;
+/**
+ * 自动处理 CURD 基本 SQL 相关类
+ */
+package com.baomidou.mybatisplus.mapper;

+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/package-info.java → src/main/java/com/baomidou/mybatisplus/package-info.java

@@ -1,4 +1,4 @@
-/**
- * mybatis-plus 对 mybatis 功能增强,使之用起来更加顺手。
- */
-package com.baomidou.mybatisplus;
+/**
+ * mybatis-plus 对 mybatis 功能增强,使之用起来更加顺手。
+ */
+package com.baomidou.mybatisplus;

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/CachePaginationInterceptor.java → src/main/java/com/baomidou/mybatisplus/plugins/CachePaginationInterceptor.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/OptimisticLockerInterceptor.java → src/main/java/com/baomidou/mybatisplus/plugins/OptimisticLockerInterceptor.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/Page.java → src/main/java/com/baomidou/mybatisplus/plugins/Page.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/PaginationInterceptor.java → src/main/java/com/baomidou/mybatisplus/plugins/PaginationInterceptor.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/PerformanceInterceptor.java → src/main/java/com/baomidou/mybatisplus/plugins/PerformanceInterceptor.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/SqlExplainInterceptor.java → src/main/java/com/baomidou/mybatisplus/plugins/SqlExplainInterceptor.java


+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/package-info.java → src/main/java/com/baomidou/mybatisplus/plugins/package-info.java

@@ -1,4 +1,4 @@
-/**
- * mybatis 插件相关类
- */
-package com.baomidou.mybatisplus.plugins;
+/**
+ * mybatis 插件相关类
+ */
+package com.baomidou.mybatisplus.plugins;

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/DialectFactory.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/DialectFactory.java


+ 40 - 40
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/IDialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/IDialect.java

@@ -1,40 +1,40 @@
-/**
- * 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.plugins.pagination;
-
-/**
- * <p>
- * 数据库 分页语句组装接口
- * </p>
- *
- * @author hubin
- * @Date 2016-01-23
- */
-public interface IDialect {
-
-    /**
-     * 组装分页语句
-     *
-     * @param originalSql
-     *            原始语句
-     * @param offset
-     *            偏移量
-     * @param limit
-     *            界限
-     * @return 分页语句
-     */
-    String buildPaginationSql(String originalSql, int offset, int limit);
-}
+/**
+ * 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.plugins.pagination;
+
+/**
+ * <p>
+ * 数据库 分页语句组装接口
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-01-23
+ */
+public interface IDialect {
+
+    /**
+     * 组装分页语句
+     *
+     * @param originalSql
+     *            原始语句
+     * @param offset
+     *            偏移量
+     * @param limit
+     *            界限
+     * @return 分页语句
+     */
+    String buildPaginationSql(String originalSql, int offset, int limit);
+}

+ 217 - 217
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/Pagination.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/Pagination.java

@@ -1,217 +1,217 @@
-/**
- * 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.plugins.pagination;
-
-import java.io.Serializable;
-
-import org.apache.ibatis.session.RowBounds;
-
-import com.baomidou.mybatisplus.toolkit.StringUtils;
-
-/**
- * <p>
- * 简单分页模型
- * </p>
- * 用户可以通过继承 org.apache.ibatis.session.RowBounds实现自己的分页模型<br>
- * 注意:插件仅支持RowBounds及其子类作为分页参数
- *
- * @author hubin
- * @Date 2016-01-23
- */
-public class Pagination extends RowBounds implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    /* 总数 */
-    private int total;
-
-    /* 每页显示条数,默认 10 */
-    private int size = 10;
-
-    /* 总页数 */
-    private int pages;
-
-    /* 当前页 */
-    private int current = 1;
-
-    /* 查询总记录数(默认 true) */
-    private boolean searchCount = true;
-
-    /**
-     * 开启排序(默认 true) 只在代码逻辑判断 并不截取sql分析
-     *
-     * @see com.baomidou.mybatisplus.mapper.SqlHelper fillWrapper
-     **/
-    private boolean openSort = true;
-
-    /**
-     * 查询总数优化(默认 false 该属性只针对于Optimize.DEFAULT有效)
-     *
-     * @see com.baomidou.mybatisplus.enums.Optimize
-     *
-     */
-    private boolean optimizeCount = false;
-
-    /**
-     * <p>
-     * SQL 排序 ORDER BY 字段,例如: id DESC(根据id倒序查询)
-     * </p>
-     * <p>
-     * DESC 表示按倒序排序(即:从大到小排序)<br>
-     * ASC 表示按正序排序(即:从小到大排序)
-     * </p>
-     */
-    private String orderByField;
-
-    /**
-     * 是否为升序 ASC( 默认: true )
-     */
-    private boolean isAsc = true;
-
-    public Pagination() {
-        super();
-    }
-
-    /**
-     * <p>
-     * 分页构造函数
-     * </p>
-     *
-     * @param current
-     *            当前页
-     * @param size
-     *            每页显示条数
-     */
-    public Pagination(int current, int size) {
-        this(current, size, true);
-    }
-
-    public Pagination(int current, int size, boolean searchCount) {
-        this(current, size, searchCount, true);
-    }
-
-    public Pagination(int current, int size, boolean searchCount, boolean openSort) {
-        super(offsetCurrent(current, size), size);
-        if (current > 1) {
-            this.current = current;
-        }
-        this.size = size;
-        this.searchCount = searchCount;
-        this.openSort = openSort;
-    }
-
-    protected static int offsetCurrent(int current, int size) {
-        if (current > 0) {
-            return (current - 1) * size;
-        }
-        return 0;
-    }
-
-    public int getOffsetCurrent() {
-        return offsetCurrent(this.current, this.size);
-    }
-
-    public boolean hasPrevious() {
-        return this.current > 1;
-    }
-
-    public boolean hasNext() {
-        return this.current < this.pages;
-    }
-
-    public int getTotal() {
-        return total;
-    }
-
-    public void setTotal(int total) {
-        this.total = total;
-    }
-
-    public int getSize() {
-        return size;
-    }
-
-    public void setSize(int size) {
-        this.size = size;
-    }
-
-    public int getPages() {
-        if (this.size == 0) {
-            return 0;
-        }
-        this.pages = this.total / this.size;
-        if (this.total % this.size != 0) {
-            this.pages++;
-        }
-        return this.pages;
-    }
-
-    public int getCurrent() {
-        return current;
-    }
-
-    public void setCurrent(int current) {
-        this.current = current;
-    }
-
-    public boolean isSearchCount() {
-        return searchCount;
-    }
-
-    public void setSearchCount(boolean searchCount) {
-        this.searchCount = searchCount;
-    }
-
-    public boolean isOptimizeCount() {
-        return optimizeCount;
-    }
-
-    public void setOptimizeCount(boolean optimizeCount) {
-        this.optimizeCount = optimizeCount;
-    }
-
-    public String getOrderByField() {
-        return orderByField;
-    }
-
-    public void setOrderByField(String orderByField) {
-        if (StringUtils.isNotEmpty(orderByField)) {
-            this.orderByField = orderByField;
-        }
-    }
-
-    public boolean isOpenSort() {
-        return openSort;
-    }
-
-    public void setOpenSort(boolean openSort) {
-        this.openSort = openSort;
-    }
-
-    public boolean isAsc() {
-        return isAsc;
-    }
-
-    public void setAsc(boolean isAsc) {
-        this.isAsc = isAsc;
-    }
-
-    @Override
-    public String toString() {
-        return "Pagination { total=" + total + " ,size=" + size + " ,pages=" + pages + " ,current=" + current + " }";
-    }
-
-}
+/**
+ * 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.plugins.pagination;
+
+import java.io.Serializable;
+
+import org.apache.ibatis.session.RowBounds;
+
+import com.baomidou.mybatisplus.toolkit.StringUtils;
+
+/**
+ * <p>
+ * 简单分页模型
+ * </p>
+ * 用户可以通过继承 org.apache.ibatis.session.RowBounds实现自己的分页模型<br>
+ * 注意:插件仅支持RowBounds及其子类作为分页参数
+ *
+ * @author hubin
+ * @Date 2016-01-23
+ */
+public class Pagination extends RowBounds implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /* 总数 */
+    private int total;
+
+    /* 每页显示条数,默认 10 */
+    private int size = 10;
+
+    /* 总页数 */
+    private int pages;
+
+    /* 当前页 */
+    private int current = 1;
+
+    /* 查询总记录数(默认 true) */
+    private boolean searchCount = true;
+
+    /**
+     * 开启排序(默认 true) 只在代码逻辑判断 并不截取sql分析
+     *
+     * @see com.baomidou.mybatisplus.mapper.SqlHelper fillWrapper
+     **/
+    private boolean openSort = true;
+
+    /**
+     * 查询总数优化(默认 false 该属性只针对于Optimize.DEFAULT有效)
+     *
+     * @see com.baomidou.mybatisplus.enums.Optimize
+     *
+     */
+    private boolean optimizeCount = false;
+
+    /**
+     * <p>
+     * SQL 排序 ORDER BY 字段,例如: id DESC(根据id倒序查询)
+     * </p>
+     * <p>
+     * DESC 表示按倒序排序(即:从大到小排序)<br>
+     * ASC 表示按正序排序(即:从小到大排序)
+     * </p>
+     */
+    private String orderByField;
+
+    /**
+     * 是否为升序 ASC( 默认: true )
+     */
+    private boolean isAsc = true;
+
+    public Pagination() {
+        super();
+    }
+
+    /**
+     * <p>
+     * 分页构造函数
+     * </p>
+     *
+     * @param current
+     *            当前页
+     * @param size
+     *            每页显示条数
+     */
+    public Pagination(int current, int size) {
+        this(current, size, true);
+    }
+
+    public Pagination(int current, int size, boolean searchCount) {
+        this(current, size, searchCount, true);
+    }
+
+    public Pagination(int current, int size, boolean searchCount, boolean openSort) {
+        super(offsetCurrent(current, size), size);
+        if (current > 1) {
+            this.current = current;
+        }
+        this.size = size;
+        this.searchCount = searchCount;
+        this.openSort = openSort;
+    }
+
+    protected static int offsetCurrent(int current, int size) {
+        if (current > 0) {
+            return (current - 1) * size;
+        }
+        return 0;
+    }
+
+    public int getOffsetCurrent() {
+        return offsetCurrent(this.current, this.size);
+    }
+
+    public boolean hasPrevious() {
+        return this.current > 1;
+    }
+
+    public boolean hasNext() {
+        return this.current < this.pages;
+    }
+
+    public int getTotal() {
+        return total;
+    }
+
+    public void setTotal(int total) {
+        this.total = total;
+    }
+
+    public int getSize() {
+        return size;
+    }
+
+    public void setSize(int size) {
+        this.size = size;
+    }
+
+    public int getPages() {
+        if (this.size == 0) {
+            return 0;
+        }
+        this.pages = this.total / this.size;
+        if (this.total % this.size != 0) {
+            this.pages++;
+        }
+        return this.pages;
+    }
+
+    public int getCurrent() {
+        return current;
+    }
+
+    public void setCurrent(int current) {
+        this.current = current;
+    }
+
+    public boolean isSearchCount() {
+        return searchCount;
+    }
+
+    public void setSearchCount(boolean searchCount) {
+        this.searchCount = searchCount;
+    }
+
+    public boolean isOptimizeCount() {
+        return optimizeCount;
+    }
+
+    public void setOptimizeCount(boolean optimizeCount) {
+        this.optimizeCount = optimizeCount;
+    }
+
+    public String getOrderByField() {
+        return orderByField;
+    }
+
+    public void setOrderByField(String orderByField) {
+        if (StringUtils.isNotEmpty(orderByField)) {
+            this.orderByField = orderByField;
+        }
+    }
+
+    public boolean isOpenSort() {
+        return openSort;
+    }
+
+    public void setOpenSort(boolean openSort) {
+        this.openSort = openSort;
+    }
+
+    public boolean isAsc() {
+        return isAsc;
+    }
+
+    public void setAsc(boolean isAsc) {
+        this.isAsc = isAsc;
+    }
+
+    @Override
+    public String toString() {
+        return "Pagination { total=" + total + " ,size=" + size + " ,pages=" + pages + " ,current=" + current + " }";
+    }
+
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/DB2Dialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/DB2Dialect.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/H2Dialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/H2Dialect.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/HSQLDialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/HSQLDialect.java


+ 37 - 37
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/MySqlDialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/MySqlDialect.java

@@ -1,37 +1,37 @@
-/**
- * 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.plugins.pagination.dialects;
-
-import com.baomidou.mybatisplus.plugins.pagination.IDialect;
-
-/**
- * <p>
- * MYSQL 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @Date 2016-01-23
- */
-public class MySqlDialect implements IDialect {
-
-    public static final MySqlDialect INSTANCE = new MySqlDialect();
-
-    public String buildPaginationSql(String originalSql, int offset, int limit) {
-        StringBuilder sql = new StringBuilder(originalSql);
-        sql.append(" LIMIT ").append(offset).append(",").append(limit);
-        return sql.toString();
-    }
-}
+/**
+ * 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.plugins.pagination.dialects;
+
+import com.baomidou.mybatisplus.plugins.pagination.IDialect;
+
+/**
+ * <p>
+ * MYSQL 数据库分页语句组装实现
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-01-23
+ */
+public class MySqlDialect implements IDialect {
+
+    public static final MySqlDialect INSTANCE = new MySqlDialect();
+
+    public String buildPaginationSql(String originalSql, int offset, int limit) {
+        StringBuilder sql = new StringBuilder(originalSql);
+        sql.append(" LIMIT ").append(offset).append(",").append(limit);
+        return sql.toString();
+    }
+}

+ 39 - 39
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/OracleDialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/OracleDialect.java

@@ -1,39 +1,39 @@
-/**
- * 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.plugins.pagination.dialects;
-
-import com.baomidou.mybatisplus.plugins.pagination.IDialect;
-
-/**
- * <p>
- * ORACLE 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @Date 2016-01-23
- */
-public class OracleDialect implements IDialect {
-
-    public static final OracleDialect INSTANCE = new OracleDialect();
-
-    public String buildPaginationSql(String originalSql, int offset, int limit) {
-        StringBuilder sql = new StringBuilder();
-        sql.append("SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( ");
-        sql.append(originalSql).append(" ) TMP WHERE ROWNUM <=").append((offset >= 1) ? (offset + limit) : limit);
-        sql.append(") WHERE ROW_ID > ").append(offset);
-        return sql.toString();
-    }
-}
+/**
+ * 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.plugins.pagination.dialects;
+
+import com.baomidou.mybatisplus.plugins.pagination.IDialect;
+
+/**
+ * <p>
+ * ORACLE 数据库分页语句组装实现
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-01-23
+ */
+public class OracleDialect implements IDialect {
+
+    public static final OracleDialect INSTANCE = new OracleDialect();
+
+    public String buildPaginationSql(String originalSql, int offset, int limit) {
+        StringBuilder sql = new StringBuilder();
+        sql.append("SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( ");
+        sql.append(originalSql).append(" ) TMP WHERE ROWNUM <=").append((offset >= 1) ? (offset + limit) : limit);
+        sql.append(") WHERE ROW_ID > ").append(offset);
+        return sql.toString();
+    }
+}

+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/PostgreDialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/PostgreDialect.java


+ 0 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/SQLServer2005Dialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/SQLServer2005Dialect.java


+ 38 - 38
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/SQLServerDialect.java → src/main/java/com/baomidou/mybatisplus/plugins/pagination/dialects/SQLServerDialect.java

@@ -1,38 +1,38 @@
-/**
- * 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.plugins.pagination.dialects;
-
-import com.baomidou.mybatisplus.plugins.pagination.IDialect;
-
-/**
- * <p>
- * SQLServer 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @Date 2016-03-23
- */
-public class SQLServerDialect implements IDialect {
-
-    public static final SQLServerDialect INSTANCE = new SQLServerDialect();
-
-    public String buildPaginationSql(String originalSql, int offset, int limit) {
-        StringBuilder sql = new StringBuilder(originalSql);
-        sql.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ");
-        sql.append(limit).append(" ROWS ONLY");
-        return sql.toString();
-    }
-}
+/**
+ * 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.plugins.pagination.dialects;
+
+import com.baomidou.mybatisplus.plugins.pagination.IDialect;
+
+/**
+ * <p>
+ * SQLServer 数据库分页语句组装实现
+ * </p>
+ *
+ * @author hubin
+ * @Date 2016-03-23
+ */
+public class SQLServerDialect implements IDialect {
+
+    public static final SQLServerDialect INSTANCE = new SQLServerDialect();
+
+    public String buildPaginationSql(String originalSql, int offset, int limit) {
+        StringBuilder sql = new StringBuilder(originalSql);
+        sql.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ");
+        sql.append(limit).append(" ROWS ONLY");
+        return sql.toString();
+    }
+}

Some files were not shown because too many files changed in this diff