为生成的实体类增加serialVersionUID字段

This commit is contained in:
hanjinfeng39 2024-01-20 11:59:22 +08:00
parent 78ab827d42
commit c50a990a69
5 changed files with 54 additions and 0 deletions

View File

@ -77,6 +77,11 @@ public class EntityConfig implements Serializable {
*/
private String dataSource;
/**
* 项目jdk版本
*/
private int jdkVersion;
/**
* 获取类前缀
*/
@ -229,6 +234,21 @@ public class EntityConfig implements Serializable {
return this;
}
/**
* 获取项目jdk版本
*/
public int getJdkVersion() {
return jdkVersion;
}
/**
* 设置项目jdk版本
*/
public EntityConfig setJdkVersion(int jdkVersion) {
this.jdkVersion = jdkVersion;
return this;
}
public enum SwaggerVersion {
FOX("FOX"),

View File

@ -942,6 +942,20 @@ public class GlobalConfig implements Serializable {
getEntityConfig().setDataSource(dataSource);
}
/**
* @see EntityConfig#getJdkVersion()
*/
public int getEntityJdkVersion() {
return getEntityConfig().getJdkVersion();
}
/**
* @see EntityConfig#setJdkVersion(int)
*/
public void setEntityJdkVersion(int jdkVersion) {
getEntityConfig().setJdkVersion(jdkVersion);
}
public boolean isMapperGenerateEnable() {
return mapperGenerateEnable;
}

View File

@ -69,6 +69,7 @@ public class TableDefGenerator implements IGenerator {
params.put("packageConfig", packageConfig);
params.put("tableDefConfig", tableDefConfig);
params.put("javadocConfig", globalConfig.getJavadocConfig());
params.put("entityConfig", globalConfig.getEntityConfig());
params.putAll(globalConfig.getCustomConfig());
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, tableDefJavaFile);

View File

@ -2,6 +2,7 @@
#set(withSwagger = entityConfig.isWithSwagger())
#set(swaggerVersion = entityConfig.getSwaggerVersion())
#set(withActiveRecord = entityConfig.isWithActiveRecord())
#set(jdkVersion = entityConfig.getJdkVersion())
#set(entityClassName = table.buildEntityClassName())
package #(packageConfig.entityPackage);
@ -30,6 +31,9 @@ import lombok.Data;
import lombok.NoArgsConstructor;
#end
#end
#if(jdkVersion >= 14)
import java.io.Serial;
#end
/**
* #(table.getComment()) 实体类。
@ -58,6 +62,11 @@ import lombok.NoArgsConstructor;
#(table.buildTableAnnotation())
public class #(entityClassName)#if(withActiveRecord) extends Model<#(entityClassName)>#else#(table.buildExtends())#(table.buildImplements())#end {
#if(jdkVersion >= 14)
@Serial
#end
private static final long serialVersionUID = 1L;
#for(column : table.columns)
#set(comment = javadocConfig.formatColumnComment(column.comment))
#if(isNotBlank(comment))

View File

@ -1,10 +1,15 @@
#set(tableDefClassName = table.buildTableDefClassName())
#set(schema = table.schema == null ? "" : table.schema)
#set(jdkVersion = entityConfig.getJdkVersion())
package #(packageConfig.tableDefPackage);
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.table.TableDef;
#if(jdkVersion >= 14)
import java.io.Serial;
#end
/**
* #(table.getComment()) 表定义层。
*
@ -13,6 +18,11 @@ import com.mybatisflex.core.table.TableDef;
*/
public class #(tableDefClassName) extends TableDef {
#if(jdkVersion >= 14)
@Serial
#end
private static final long serialVersionUID = 1L;
/**
* #(table.getComment())
*/