Skip to content

Commit

Permalink
支持Serial注解.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Feb 23, 2025
1 parent 02750cd commit d21b78e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ private Entity() {
@Getter
private boolean serialVersionUID = true;

/**
* 是否启用 {@link java.io.Serial} (需JAVA 14) 注解
*
* @since 3.5.11
*/
@Getter
private boolean serialAnnotation;

/**
* 【实体】是否生成字段常量(默认 false)<br>
* -----------------------------------<br>
Expand Down Expand Up @@ -412,6 +420,7 @@ public Map<String, Object> renderData(@NotNull TableInfo tableInfo) {
data.put("versionFieldName", this.versionColumnName);
data.put("activeRecord", this.activeRecord);
data.put("entitySerialVersionUID", this.serialVersionUID);
data.put("entitySerialAnnotation", this.serialAnnotation);
data.put("entityColumnConstant", this.columnConstant);
data.put("entityBuilderModel", this.chain);
data.put("chainModel", this.chain);
Expand Down Expand Up @@ -500,6 +509,18 @@ public Builder disableSerialVersionUID() {
return this;
}

/**
* 启用生成 {@link java.io.Serial} (需JAVA 14)
* <p>当开启了 {@link #serialVersionUID} 时,会增加 {@link java.io.Serial} 注解在此字段上</p>
*
* @return this
* @since 3.5.11
*/
public Builder enableSerialAnnotation() {
this.entity.serialAnnotation = true;
return this;
}

/**
* 开启生成字段常量
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ public void importPackage() {
}
if (entity.isSerialVersionUID() || entity.isActiveRecord()) {
this.importPackages.add(Serializable.class.getCanonicalName());
if (entity.isSerialAnnotation()) {
this.importPackages.add("java.io.Serial");
}
}
if (this.isConvert()) {
this.importPackages.add(TableName.class.getCanonicalName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class ${entity} {
<% } %>
<% if(entitySerialVersionUID){ %>

<% if(entitySerialAnnotation) { %>
@Serial
<% } %>
private static final long serialVersionUID = 1L;
<% } %>
<% var keyPropertyName; %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class #(entity) {
#end
#if(entitySerialVersionUID)

#if(entitySerialAnnotation)
@Serial
#end
private static final long serialVersionUID = 1L;
#end
### ---------- BEGIN 字段循环遍历 ----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ${entity} {
</#if>
<#if entitySerialVersionUID>

<#if entitySerialAnnotation>
@Serial
</#if>
private static final long serialVersionUID = 1L;
</#if>
<#-- ---------- BEGIN 字段循环遍历 ---------->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class ${entity} {
#end
#if(${entitySerialVersionUID})

#if(${entitySerialAnnotation})
@Serial
#end
private static final long serialVersionUID = 1L;
#end
## ---------- BEGIN 字段循环遍历 ----------
Expand Down

0 comments on commit d21b78e

Please sign in to comment.