From 4c7a7e2452ddf3f5cb5a4129dc19f137d6b0d925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Thu, 16 Oct 2025 20:42:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(entity):=E4=BC=98=E5=8C=96=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=B1=BB=E6=A8=A1=E6=9D=BF=E6=B3=A8=E8=A7=A3=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了时间类型字段的冗余声明注解 - 合并了条件判断逻辑,减少嵌套层级- 调整了注释与注解的排列顺序 - 统一处理字段注解生成流程 - 简化了主键和填充字段的注解条件判断 -优化了代码格式,提高可读性 --- .../generator/templates/entity.java.btl | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/gxwebsoft/generator/templates/entity.java.btl b/src/test/java/com/gxwebsoft/generator/templates/entity.java.btl index 2bd35ce..bb9b781 100644 --- a/src/test/java/com/gxwebsoft/generator/templates/entity.java.btl +++ b/src/test/java/com/gxwebsoft/generator/templates/entity.java.btl @@ -53,27 +53,22 @@ public class ${entity} implements Serializable { <% for(field in table.fields) { var keyPropertyName = field.keyFlag ? field.propertyName : null; %> - -<% if(isNotEmpty(field.comment)) { %> -<% if(swagger2) { %> @Schema(description = "${field.comment}") +<% if(isNotEmpty(field.comment)) { %><% if(swagger2) { %> @Schema(description = "${field.comment}") <% }else{ %> /** * ${field.comment} */ -<% } -}%><% /* 为时间类型字段添加日期格式化注解并声明字段 */ %><% if(field.propertyType == 'LocalDateTime' || field.propertyType == 'LocalDate' || field.propertyType == 'LocalTime' || field.propertyType == 'Date') { %><% if(field.propertyType == 'LocalDateTime') { %> @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") +<% } %><% } %><% /* 为时间类型字段添加日期格式化注解 */ %><% if(field.propertyType == 'LocalDateTime' || field.propertyType == 'LocalDate' || field.propertyType == 'LocalTime' || field.propertyType == 'Date') { %><% if(field.propertyType == 'LocalDateTime') { %> @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") <% } else if(field.propertyType == 'LocalDate') { %> @JsonFormat(pattern = "yyyy-MM-dd") <% } else if(field.propertyType == 'LocalTime') { %> @JsonFormat(pattern = "HH:mm:ss") <% } else if(field.propertyType == 'Date') { %> @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") -<% } %><% } %><% /* 主键 */ %><% if(field.keyFlag) { %><% if(field.keyIdentityFlag) { %> @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO) +<% } %><% } %><% /* 添加其他注解(主键、字段填充等) */ %><% if(field.keyFlag) { %><% if(field.keyIdentityFlag) { %> @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO) <% } else if(isNotEmpty(idType)) { %> @TableId(value = "${field.annotationColumnName}", type = IdType.${idType}) <% } else if(field.convert) { %> @TableId("${field.annotationColumnName}") -<% } %><% /* 普通字段 */ %> -<% } else if(isNotEmpty(field.fill)) { %><% if(field.convert){ %> @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}) +<% } %><% } else if(isNotEmpty(field.fill)) { %><% if(field.convert){ %> @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}) <% }else{ %> @TableField(fill = FieldFill.${field.fill}) -<% } %> -<% } else if(field.convert) { %> @TableField("${field.annotationColumnName}") -<% } %><% /* 乐观锁注解 */ %><% if(versionFieldName!'' == field.name) { %> @Version -<% } %><% /* 逻辑删除注解 */ %><% if(logicDeleteFieldName!'' == field.name) { %> @TableLogic +<% } %><% } else if(field.convert) { %> @TableField("${field.annotationColumnName}") +<% } %><% if(versionFieldName!'' == field.name) { %> @Version +<% } %><% if(logicDeleteFieldName!'' == field.name) { %> @TableLogic <% } %> private ${field.propertyType} ${field.propertyName}; <% } %> <% /** -----------END 字段循环遍历----------- **/ %>