Ver código fonte

代码生成实体根据模板区分不同父字段

RuoYi 5 anos atrás
pai
commit
69cc7a4111

+ 6 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java

@@ -44,6 +44,12 @@ public class GenConstants
     public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by",
             "update_time", "remark" };
 
+    /** Entity基类字段 */
+    public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
+
+    /** Tree基类字段 */
+    public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors" };
+
     /** 文本框 */
     public static final String HTML_INPUT = "input";
 

+ 14 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java

@@ -252,4 +252,18 @@ public class GenTable extends BaseEntity
     {
         return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
     }
+
+    public boolean isSuperColumn(String javaField)
+    {
+        return isSuperColumn(this.tplCategory, javaField);
+    }
+
+    public static boolean isSuperColumn(String tplCategory, String javaField)
+    {
+        if (isTree(tplCategory))
+        {
+            StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.TREE_ENTITY);
+        }
+        return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
+    }
 }

+ 2 - 2
ruoyi-generator/src/main/resources/vm/java/domain.java.vm

@@ -28,7 +28,7 @@ public class ${ClassName} extends ${Entity}
     private static final long serialVersionUID = 1L;
 
 #foreach ($column in $columns)
-#if(!$column.superColumn)
+#if(!$table.isSuperColumn($column.javaField))
     /** $column.columnComment */
 #if($column.list)
 #set($parentheseIndex=$column.columnComment.indexOf("("))
@@ -50,7 +50,7 @@ public class ${ClassName} extends ${Entity}
 #end
 #end
 #foreach ($column in $columns)
-#if(!$column.superColumn)
+#if(!$table.isSuperColumn($column.javaField))
 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
     public void set${AttrName}($column.javaType $column.javaField) 
     {