hubin před 6 roky
rodič
revize
a701ab49bd

+ 29 - 0
CHANGELOG.md

@@ -1,5 +1,34 @@
 # CHANGELOG
 
+## [v3.1.1] 2019.04.24
+- 新增 996icu license 协议
+- 新增 mybatis-plus-dts 分布式事务 rabbit 可靠消息机制
+- 新增 DynamicTableNameParser 解析器、支持动态表名
+- 优化 getOne 日志打印
+- sql 优化跳过存储过程
+- 优化分页查询(count为0不继续查询)
+- 修复分页一级缓存无法继续翻页问题
+- MybatisMapWrapperFactory 自动注入
+- 支持纯注解下使用 IPage 的子类作为返回值
+- 逻辑删除不再需要 LogicInject
+- GlobalConfig 加入 enableSqlRunner 属性控制是否注入 SqlRunner ,默认 false
+- SqlParser注解不再需要全局设置参数才会缓存,以及支持注解在 mapper 上
+- GlobalConfig 的 sqlParserCache 设置为过时
+- mybatis 升级到 3.5.1 , mybatis-spring 升级到 2.0.1 , jsqlparser 降级到 1.2
+- ISqlInjector 接口 移除 injectSqlRunner 方法
+- SqlFormatter 类设置为过时
+- 解决自动注入的 method 的 SqlCommandType 在逻辑删除下混乱问题
+- 新增 AlwaysUpdateSomeColumnById 选装件
+- SFunction 继承 Function
+- DbConfig 的 columnLike 和 dbType 属性设置为过时
+- DbConfig 新增 schema 和 columnFormat 属性
+- TableField 注解增加 keepGlobalFormat 属性
+- TableName 注解增加 schema 和 keepGlobalPrefix 属性
+- fixed bug tmp文件格式错乱 github #1048
+- 处理表/字段名称抽象 INameConvert 接口策略 github #1038
+- DB2支持动态 schema 配置 github #1035
+
+
 ## [v3.1.0] 2019.02.24
 - 升级 `mybatis` 到 `3.5.0` 版本
 - 升级 `mybatis-spring` 到 `2.0.0` 版本

+ 1 - 1
build.gradle

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

+ 44 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/INameConvert.java

@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (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>
+ * https://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.generator.config.po.TableField;
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+
+/**
+ * 名称转换接口类
+ *
+ * @author hubin
+ * @since 2017-01-20
+ */
+public interface INameConvert {
+
+    /**
+     * 执行实体名称转换
+     *
+     * @param tableInfo 表信息对象
+     * @return
+     */
+    String entityNameConvert(TableInfo tableInfo);
+
+    /**
+     * 执行属性名称转换
+     *
+     * @param field 表字段对象,如果属性表字段命名不一致注意 convert 属性的设置
+     * @return
+     */
+    String propertyNameConvert(TableField field);
+}

+ 4 - 1
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java

@@ -40,7 +40,6 @@ import lombok.experimental.Accessors;
 @Data
 @Accessors(chain = true)
 public class StrategyConfig {
-
     /**
      * 是否大写命名
      */
@@ -49,6 +48,10 @@ public class StrategyConfig {
      * 是否跳过视图
      */
     private boolean skipView = false;
+    /**
+     * 名称转换
+     */
+    private INameConvert nameConvert;
     /**
      * 数据库表映射到实体的命名策略
      */

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

@@ -19,13 +19,7 @@ import com.baomidou.mybatisplus.annotation.DbType;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.generator.InjectionConfig;
-import com.baomidou.mybatisplus.generator.config.ConstVal;
-import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
-import com.baomidou.mybatisplus.generator.config.GlobalConfig;
-import com.baomidou.mybatisplus.generator.config.IDbQuery;
-import com.baomidou.mybatisplus.generator.config.PackageConfig;
-import com.baomidou.mybatisplus.generator.config.StrategyConfig;
-import com.baomidou.mybatisplus.generator.config.TemplateConfig;
+import com.baomidou.mybatisplus.generator.config.*;
 import com.baomidou.mybatisplus.generator.config.po.TableField;
 import com.baomidou.mybatisplus.generator.config.po.TableFill;
 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
@@ -320,7 +314,14 @@ public class ConfigBuilder {
     private List<TableInfo> processTable(List<TableInfo> tableList, NamingStrategy strategy, StrategyConfig config) {
         String[] tablePrefix = config.getTablePrefix();
         for (TableInfo tableInfo : tableList) {
-            String entityName = NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategy, tablePrefix));
+            String entityName;
+            INameConvert nameConvert = strategyConfig.getNameConvert();
+            if (null != nameConvert) {
+                // 自定义处理实体名称
+                entityName = nameConvert.entityNameConvert(tableInfo);
+            } else {
+                entityName = NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategy, tablePrefix));
+            }
             if (StringUtils.isNotEmpty(globalConfig.getEntityName())) {
                 tableInfo.setConvert(true);
                 tableInfo.setEntityName(String.format(globalConfig.getEntityName(), entityName));
@@ -409,16 +410,25 @@ public class ConfigBuilder {
             if (DbType.POSTGRE_SQL == dbQuery.dbType()) {
                 String schema = dataSourceConfig.getSchemaName();
                 if (schema == null) {
-                    //pg默认schema=public
+                    //pg 默认 schema=public
                     schema = "public";
                     dataSourceConfig.setSchemaName(schema);
                 }
                 tablesSql = String.format(tablesSql, schema);
             }
+            if (DbType.DB2 == dbQuery.dbType()) {
+                String schema = dataSourceConfig.getSchemaName();
+                if (schema == null) {
+                    //db2 默认 schema=current schema
+                    schema = "current schema";
+                    dataSourceConfig.setSchemaName(schema);
+                }
+                tablesSql = String.format(tablesSql, schema);
+            }
             //oracle数据库表太多,出现最大游标错误
             else if (DbType.ORACLE == dbQuery.dbType()) {
                 String schema = dataSourceConfig.getSchemaName();
-                //oracle默认用户的schema=username
+                //oracle 默认 schema=username
                 if (schema == null) {
                     schema = dataSourceConfig.getUsername().toUpperCase();
                     dataSourceConfig.setSchemaName(schema);
@@ -494,7 +504,7 @@ public class ConfigBuilder {
                 includeTableList = tableList;
             }
             // 性能优化,只处理需执行表字段 github issues/219
-            includeTableList.forEach(ti -> convertTableFields(ti, config.getColumnNaming()));
+            includeTableList.forEach(ti -> convertTableFields(ti, config));
         } catch (SQLException e) {
             e.printStackTrace();
         }
@@ -518,10 +528,10 @@ public class ConfigBuilder {
      * 将字段信息与表信息关联
      *
      * @param tableInfo 表信息
-     * @param strategy  命名策略
+     * @param config    命名策略
      * @return ignore
      */
-    private TableInfo convertTableFields(TableInfo tableInfo, NamingStrategy strategy) {
+    private TableInfo convertTableFields(TableInfo tableInfo, StrategyConfig config) {
         boolean haveId = false;
         List<TableField> fieldList = new ArrayList<>();
         List<TableField> commonFieldList = new ArrayList<>();
@@ -532,6 +542,8 @@ public class ConfigBuilder {
             Set<String> h2PkColumns = new HashSet<>();
             if (DbType.POSTGRE_SQL == dbType) {
                 tableFieldsSql = String.format(tableFieldsSql, dataSourceConfig.getSchemaName(), tableName);
+            } else if (DbType.DB2 == dbType) {
+                tableFieldsSql = String.format(tableFieldsSql, dataSourceConfig.getSchemaName(), tableName);
             } else if (DbType.ORACLE == dbType) {
                 tableName = tableName.toUpperCase();
                 tableFieldsSql = String.format(tableFieldsSql.replace("#schema", dataSourceConfig.getSchemaName()), tableName);
@@ -591,7 +603,12 @@ public class ConfigBuilder {
                     // 处理其它信息
                     field.setName(columnName);
                     field.setType(results.getString(dbQuery.fieldType()));
-                    field.setPropertyName(strategyConfig, processName(field.getName(), strategy));
+                    INameConvert nameConvert = strategyConfig.getNameConvert();
+                    if (null != nameConvert) {
+                        field.setPropertyName(nameConvert.propertyNameConvert(field));
+                    } else {
+                        field.setPropertyName(strategyConfig, processName(field.getName(), config.getNaming()));
+                    }
                     field.setColumnType(dataSourceConfig.getTypeConvert().processTypeConvert(globalConfig, field.getType()));
                     field.setComment(results.getString(dbQuery.fieldComment()));
                     if (strategyConfig.includeSuperEntityColumns(field.getName())) {
@@ -665,9 +682,9 @@ public class ConfigBuilder {
     /**
      * 处理表/字段名称
      *
-     * @param name ignore
+     * @param name     ignore
      * @param strategy ignore
-     * @param prefix ignore
+     * @param prefix   ignore
      * @return 根据策略返回处理后的名称
      */
     private String processName(String name, NamingStrategy strategy, String[] prefix) {

+ 2 - 2
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/querys/DB2Query.java

@@ -34,13 +34,13 @@ public class DB2Query extends AbstractDbQuery {
 
     @Override
     public String tablesSql() {
-        return "SELECT * FROM SYSCAT.TABLES where tabschema=current schema";
+        return "SELECT * FROM SYSCAT.TABLES where tabschema=%s";
     }
 
 
     @Override
     public String tableFieldsSql() {
-        return "SELECT *  FROM syscat.columns WHERE tabschema=current schema AND tabname='%s'";
+        return "SELECT *  FROM syscat.columns WHERE tabschema=%s AND tabname='%s'";
     }
 
 

+ 88 - 89
mybatis-plus-generator/src/main/resources/templates/entity.java.vm

@@ -1,17 +1,16 @@
-package ${package.Entity}import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.experimental.Accessors;
+package ${package.Entity};
 
-;
 #foreach($pkg in ${table.importPackages})
-    ${pkg}
-;
+import ${pkg};
 #end
 #if(${swagger2})
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 #end
 #if(${entityLombokModel})
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
 #end
 
 /**
@@ -24,25 +23,25 @@ import lombok.experimental.Accessors;
  */
 #if(${entityLombokModel})
 @Data
-    #if(${superEntityClass})
-    @EqualsAndHashCode(callSuper = true)
-    #else
-    @EqualsAndHashCode(callSuper = false)
-    #end
+#if(${superEntityClass})
+@EqualsAndHashCode(callSuper = true)
+#else
+@EqualsAndHashCode(callSuper = false)
+#end
 @Accessors(chain = true)
 #end
 #if(${table.convert})
 @TableName("${table.name}")
 #end
 #if(${swagger2})
-@ApiModel(value = "${entity}对象", description = "$!{table.comment}")
+@ApiModel(value="${entity}对象", description="$!{table.comment}")
 #end
 #if(${superEntityClass})
 public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
 #elseif(${activeRecord})
 public class ${entity} extends Model<${entity}> {
 #else
-public class ${entity} implements Serializable{
+public class ${entity} implements Serializable {
 #end
 
 #if(${entitySerialVersionUID})
@@ -51,104 +50,104 @@ private static final long serialVersionUID=1L;
 ## ----------  BEGIN 字段循环遍历  ----------
 #foreach($field in ${table.fields})
 
-    #if(${field.keyFlag})
-        #set($keyPropertyName=${field.propertyName})
-    #end
-    #if("$!field.comment" != "")
-        #if(${swagger2})
-        @ApiModelProperty(value = "${field.comment}")
-        #else
-        /**
-         * ${field.comment}
-         */
-        #end
-    #end
-    #if(${field.keyFlag})
-    ## 主键
-        #if(${field.keyIdentityFlag})
-        @TableId(value = "${field.name}", type = IdType.AUTO)
-        #elseif(!$null.isNull(${idType}) && "$!idType" != "")
-        @TableId(value = "${field.name}", type = IdType.${idType})
-        #elseif(${field.convert})
-        @TableId("${field.name}")
-        #end
-    ## 普通字段
-    #elseif(${field.fill})
-    ## -----   存在字段填充设置   -----
-        #if(${field.convert})
-        @TableField(value = "${field.name}", fill = FieldFill.${field.fill})
-        #else
-        @TableField(fill = FieldFill.${field.fill})
-        #end
-    #elseif(${field.convert})
+#if(${field.keyFlag})
+#set($keyPropertyName=${field.propertyName})
+#end
+#if("$!field.comment" != "")
+#if(${swagger2})
+    @ApiModelProperty(value = "${field.comment}")
+#else
+    /**
+     * ${field.comment}
+     */
+#end
+#end
+#if(${field.keyFlag})
+## 主键
+#if(${field.keyIdentityFlag})
+    @TableId(value = "${field.name}", type = IdType.AUTO)
+#elseif(!$null.isNull(${idType}) && "$!idType" != "")
+    @TableId(value = "${field.name}", type = IdType.${idType})
+#elseif(${field.convert})
+    @TableId("${field.name}")
+#end
+## 普通字段
+#elseif(${field.fill})
+## -----   存在字段填充设置   -----
+#if(${field.convert})
+    @TableField(value = "${field.name}", fill = FieldFill.${field.fill})
+#else
+    @TableField(fill = FieldFill.${field.fill})
+#end
+#elseif(${field.convert})
     @TableField("${field.name}")
-    #end
+#end
 ## 乐观锁注解
-    #if(${versionFieldName}==${field.name})
+#if(${versionFieldName}==${field.name})
     @Version
-    #end
+#end
 ## 逻辑删除注解
-    #if(${logicDeleteFieldName}==${field.name})
+#if(${logicDeleteFieldName}==${field.name})
     @TableLogic
-    #end
-private ${field.propertyType} ${field.propertyName};
+#end
+    private ${field.propertyType} ${field.propertyName};
 #end
 ## ----------  END 字段循环遍历  ----------
 
 #if(!${entityLombokModel})
-    #foreach($field in ${table.fields})
-        #if(${field.propertyType.equals("boolean")})
-            #set($getprefix="is")
-        #else
-            #set($getprefix="get")
-        #end
+#foreach($field in ${table.fields})
+#if(${field.propertyType.equals("boolean")})
+#set($getprefix="is")
+#else
+#set($getprefix="get")
+#end
 
-    public ${field.propertyType} ${getprefix}${field.capitalName}(){
+    public ${field.propertyType} ${getprefix}${field.capitalName}() {
         return ${field.propertyName};
-        }
+    }
 
-        #if(${entityBuilderModel})
-        public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}){
-        #else
-        public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
-        #end
+#if(${entityBuilderModel})
+    public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
+#else
+    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
+#end
         this.${field.propertyName} = ${field.propertyName};
-        #if(${entityBuilderModel})
-            return this;
-        #end
-        }
-    #end
+#if(${entityBuilderModel})
+        return this;
+#end
+    }
+#end
 #end
 
 #if(${entityColumnConstant})
-    #foreach($field in ${table.fields})
-    public static final String ${field.name.toUpperCase()} ="${field.name}";
+#foreach($field in ${table.fields})
+    public static final String ${field.name.toUpperCase()} = "${field.name}";
 
-    #end
+#end
 #end
 #if(${activeRecord})
-@Override
-protected Serializable pkVal(){
-    #if(${keyPropertyName})
+    @Override
+    protected Serializable pkVal() {
+#if(${keyPropertyName})
         return this.${keyPropertyName};
-    #else
+#else
         return null;
-    #end
+#end
     }
 
 #end
 #if(!${entityLombokModel})
-@Override
-public String toString() {
-    return "${entity}{" +
-    #foreach($field in ${table.fields})
-        #if($!{foreach.index}==0)
-            "${field.propertyName}=" + ${field.propertyName} +
-        #else
-            ", ${field.propertyName}=" + ${field.propertyName} +
-        #end
-    #end
-    "}";
-    }
+    @Override
+    public String toString() {
+        return "${entity}{" +
+#foreach($field in ${table.fields})
+#if($!{foreach.index}==0)
+        "${field.propertyName}=" + ${field.propertyName} +
+#else
+        ", ${field.propertyName}=" + ${field.propertyName} +
 #end
+#end
+        "}";
     }
+#end
+}