Explorar o código

修复beetl模板逻辑删除注解错误,补充一份kotlin模板(待修改).

nieqiuqiu %!s(int64=6) %!d(string=hai) anos
pai
achega
62c732ff89

+ 2 - 1
build.gradle.kts

@@ -70,7 +70,8 @@ val lib = mapOf(
     "velocity"                   to "org.apache.velocity:velocity-engine-core:2.0",
     "freemarker"                 to "org.freemarker:freemarker:2.3.28",
     "beetl"                      to "com.ibeetl:beetl:2.9.8",
-    "lagarto"                    to "org.jodd:jodd-lagarto:5.0.7"
+    "lagarto"                    to "org.jodd:jodd-lagarto:5.0.7",
+    "swagger-annotations"        to "io.swagger:swagger-annotations:1.5.21"
 )
 // ext
 extra["lib"] = lib

+ 1 - 0
mybatis-plus-generator/build.gradle.kts

@@ -13,4 +13,5 @@ dependencies {
     testImplementation("${lib["h2"]}")
     testImplementation("${lib["mysql"]}")
     testImplementation("${lib["logback-classic"]}")
+    testImplementation("${lib["swagger-annotations"]}")
 }

+ 1 - 1
mybatis-plus-generator/src/main/resources/templates/entity.java.btl

@@ -93,7 +93,7 @@ public class ${entity} implements Serializable {
     /*逻辑删除注解*/
     %>
     <% if(logicDeleteFieldName!'' == field.name){ %>
-    @Version
+    @TableLogic
     <% } %>
     private ${field.propertyType} ${field.propertyName};
 <% } %>

+ 119 - 0
mybatis-plus-generator/src/main/resources/templates/entity.kt.btl

@@ -0,0 +1,119 @@
+package ${package.Entity}
+<% for(pkg in table.importPackages){ %>
+import ${pkg}
+<% } %>
+<% if(swagger2){ %>
+import io.swagger.annotations.ApiModel
+import io.swagger.annotations.ApiModelProperty
+<% } %>
+/**
+ * <p>
+ * ${table.comment!}
+ * </p>
+ *
+ * @author ${author}
+ * @since ${date}
+ */
+<% if(table.convert){ %>
+@TableName("${table.name}")
+<% } %>
+<% if(swagger2){ %>
+@ApiModel(value="${entity}对象", description="${table.comment!''}")
+<% } %>
+<% if(isNotEmpty(superEntityClass)){ %>
+class ${entity} : ${superEntityClass}<% if(activeRecord){ %><${entity}><%}%>{
+<% }else if(activeRecord){ %>
+class ${entity} : Model<${entity}> {
+<% }else{ %>
+class ${entity} : Serializable {
+<% } %>
+
+<% /** -----------BEGIN 字段循环遍历----------- **/ %>
+<% for(field in table.fields){ %>
+    <%
+    if(field.keyFlag){
+        var keyPropertyName = field.propertyName;
+    }
+    %>
+
+    <% if(isNotEmpty(field.comment)){ %>
+        <% if(swagger2){ %>
+    @ApiModelProperty(value = "${field.comment}")
+        <% }else{ %>
+    /**
+     * ${field.comment}
+     */
+        <% } %>
+    <% } %>
+    <% if(field.keyFlag){ %>
+    <%
+    /*主键*/
+    %>
+        <% if(field.keyIdentityFlag){ %>
+    @TableId(value = "${field.name}", type = IdType.AUTO)
+        <% }else if(isNotEmpty(idType)){ %>
+    @TableId(value = "${field.name}", type = IdType.${idType})
+        <% }else if(field.convert){ %>
+    @TableId("${field.name}")
+         <% } %>
+    <%
+    /*普通字段*/
+    %>
+    <% }else if(isNotEmpty(field.fill)){ %>
+        <% if(field.convert){ %>
+    @TableField(value = "${field.name}", fill = FieldFill.${field.fill})
+        <% }else{ %>
+    @TableField(fill = FieldFill.${field.fill})
+        <% } %>
+    <% }else if(field.convert){ %>
+    @TableField("${field.name}")
+    <% } %>
+    <%
+    /*乐观锁注解*/
+    %>
+    <% if(versionFieldName!'' == field.name){ %>
+    @Version
+    <% } %>
+    <%
+    /*逻辑删除注解*/
+    %>
+    <% if(logicDeleteFieldName!'' == field.name){ %>
+    @TableLogic
+    <% } %>
+    var ${field.propertyName}: ${field.propertyType} ? = null
+<% } %>
+<% /** -----------END 字段循环遍历----------- **/ %>
+
+<% if(entityColumnConstant){ %>
+   <% for(field in table.fields){ %>
+    public static final String ${strutil.toUpperCase(field.name)} = "${field.name}"
+
+   <% } %>
+<% } %>
+<% if(activeRecord){ %>
+    @Override
+    override fun pkVal(): Serializable? {
+    <% if(isNotEmpty(keyPropertyName)){ %>
+        return this.${keyPropertyName}
+    <% }else{ %>
+        return null;
+    <% } %>
+    }
+
+<% } %>
+
+<% if(!entityLombokModel){ %>
+    @Override
+    override fun toString(): String  {
+        return "${entity}{" +
+    <% for(field in table.fields){ %>
+       <% if(fieldLP.index==0){ %>
+        "${field.propertyName}=" + ${field.propertyName} +
+       <% }else{ %>
+        ", ${field.propertyName}=" + ${field.propertyName} +
+       <% } %>
+    <% } %>
+        "}"
+    }
+<% } %>
+}