Bläddra i källkod

修复 github issues/377

hubin 7 år sedan
förälder
incheckning
a4b1111517

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/AbstractMethod.java

@@ -85,7 +85,7 @@ public abstract class AbstractMethod {
             if (type instanceof ParameterizedType) {
                 Type[] typeArray = ((ParameterizedType) type).getActualTypeArguments();
                 if (ArrayUtils.isNotEmpty(typeArray)) {
-                    for (Type t : typeArray) {//todo 报黄了,不改一下?
+                    for (Type t : typeArray) {
                         if (t instanceof TypeVariable || t instanceof WildcardType) {
                             break;
                         } else {

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

@@ -85,6 +85,7 @@ public class GlobalConfig {
     /**
      * 各层文件名称方式,例如: %Action 生成 UserAction
      */
+    private String entityName;
     private String mapperName;
     private String xmlName;
     private String serviceName;

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

@@ -342,31 +342,36 @@ public class ConfigBuilder {
         String[] tablePrefix = config.getTablePrefix();
         String[] fieldPrefix = config.getFieldPrefix();
         for (TableInfo tableInfo : tableList) {
-            tableInfo.setEntityName(strategyConfig, NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategy, tablePrefix)));
+            String entityName = NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategy, tablePrefix));
+            if (StringUtils.isNotEmpty(globalConfig.getEntityName())) {
+                tableInfo.setEntityName(strategyConfig, String.format(globalConfig.getEntityName(), entityName));
+            } else {
+                tableInfo.setEntityName(strategyConfig, entityName);
+            }
             if (StringUtils.isNotEmpty(globalConfig.getMapperName())) {
-                tableInfo.setMapperName(String.format(globalConfig.getMapperName(), tableInfo.getEntityName()));
+                tableInfo.setMapperName(String.format(globalConfig.getMapperName(), entityName));
             } else {
-                tableInfo.setMapperName(tableInfo.getEntityName() + ConstVal.MAPPER);
+                tableInfo.setMapperName(entityName + ConstVal.MAPPER);
             }
             if (StringUtils.isNotEmpty(globalConfig.getXmlName())) {
-                tableInfo.setXmlName(String.format(globalConfig.getXmlName(), tableInfo.getEntityName()));
+                tableInfo.setXmlName(String.format(globalConfig.getXmlName(), entityName));
             } else {
-                tableInfo.setXmlName(tableInfo.getEntityName() + ConstVal.MAPPER);
+                tableInfo.setXmlName(entityName + ConstVal.MAPPER);
             }
             if (StringUtils.isNotEmpty(globalConfig.getServiceName())) {
-                tableInfo.setServiceName(String.format(globalConfig.getServiceName(), tableInfo.getEntityName()));
+                tableInfo.setServiceName(String.format(globalConfig.getServiceName(), entityName));
             } else {
-                tableInfo.setServiceName("I" + tableInfo.getEntityName() + ConstVal.SERVICE);
+                tableInfo.setServiceName("I" + entityName + ConstVal.SERVICE);
             }
             if (StringUtils.isNotEmpty(globalConfig.getServiceImplName())) {
-                tableInfo.setServiceImplName(String.format(globalConfig.getServiceImplName(), tableInfo.getEntityName()));
+                tableInfo.setServiceImplName(String.format(globalConfig.getServiceImplName(), entityName));
             } else {
-                tableInfo.setServiceImplName(tableInfo.getEntityName() + ConstVal.SERVICE_IMPL);
+                tableInfo.setServiceImplName(entityName + ConstVal.SERVICE_IMPL);
             }
             if (StringUtils.isNotEmpty(globalConfig.getControllerName())) {
-                tableInfo.setControllerName(String.format(globalConfig.getControllerName(), tableInfo.getEntityName()));
+                tableInfo.setControllerName(String.format(globalConfig.getControllerName(), entityName));
             } else {
-                tableInfo.setControllerName(tableInfo.getEntityName() + ConstVal.CONTROLLER);
+                tableInfo.setControllerName(entityName + ConstVal.CONTROLLER);
             }
             //强制开启字段注解
             checkTableIdTableFieldAnnotation(config, tableInfo, fieldPrefix);

+ 1 - 0
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/MysqlGenerator.java

@@ -72,6 +72,7 @@ public class MysqlGenerator extends GeneratorTest {
                 //.setKotlin(true) 是否生成 kotlin 代码
                 .setAuthor("Yanghu")
             // 自定义文件命名,注意 %s 会自动填充表实体属性!
+            // .setEntityName("%sEntity");
             // .setMapperName("%sDao")
             // .setXmlName("%sDao")
             // .setServiceName("MP%sService")

+ 1 - 0
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/PostgreSQLGenerator.java

@@ -45,6 +45,7 @@ public class PostgreSQLGenerator extends GeneratorTest {
         gc.setAuthor("hubin");
 
         // 自定义文件命名,注意 %s 会自动填充表实体属性!
+        // gc.setEntityName("%sEntity");
         // gc.setMapperName("%sDao");
         // gc.setXmlName("%sDao");
         // gc.setServiceName("MP%sService");

+ 1 - 0
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/test/generator/SQLServerGenerator.java

@@ -45,6 +45,7 @@ public class SQLServerGenerator extends GeneratorTest {
         gc.setAuthor("nieqiurong");
 
         // 自定义文件命名,注意 %s 会自动填充表实体属性!
+        // gc.setEntityName("%sEntity");
         // gc.setMapperName("%sDao");
         // gc.setXmlName("%sDao");
         // gc.setServiceName("MP%sService");