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

Merge pull request !412 from hanjinfeng39/hjf
This commit is contained in:
王帅 2024-01-22 13:05:02 +00:00 committed by Gitee
commit 6dcb2295e6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 59 additions and 1 deletions

View File

@ -68,6 +68,8 @@ public class Codegen {
//设置生成 entity 并启用 Lombok //设置生成 entity 并启用 Lombok
globalConfig.setEntityGenerateEnable(true); globalConfig.setEntityGenerateEnable(true);
globalConfig.setEntityWithLombok(true); globalConfig.setEntityWithLombok(true);
//设置项目的JDK版本项目的JDK为14及以上时建议设置该项小于14则可以不设置
globalConfig.setJdkVersion(17);
//设置生成 mapper //设置生成 mapper
globalConfig.setMapperGenerateEnable(true); globalConfig.setMapperGenerateEnable(true);
@ -97,7 +99,8 @@ public class Codegen {
//设置生成 entity 并启用 Lombok //设置生成 entity 并启用 Lombok
globalConfig.enableEntity() globalConfig.enableEntity()
.setWithLombok(true); .setWithLombok(true)
.setJdkVersion(17);
//设置生成 mapper //设置生成 mapper
globalConfig.enableMapper(); globalConfig.enableMapper();
@ -292,6 +295,7 @@ globalConfig.getTemplateConfig()
| setSwaggerVersion(EntityConfig.SwaggerVersion) | Swagger 注解版本 | SwaggerVersion.FOX | | setSwaggerVersion(EntityConfig.SwaggerVersion) | Swagger 注解版本 | SwaggerVersion.FOX |
| setWithActiveRecord(boolean) | 是否生成 Active Record 模式的 Entity | false | | setWithActiveRecord(boolean) | 是否生成 Active Record 模式的 Entity | false |
| setDataSource(String) | 统一使用的数据源 | null | | setDataSource(String) | 统一使用的数据源 | null |
| setJdkVersion(int) | 设置项目的jdk版本 | 0 |
```java ```java
globalConfig.getEntityConfig() globalConfig.getEntityConfig()

View File

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

View File

@ -942,6 +942,20 @@ public class GlobalConfig implements Serializable {
getEntityConfig().setDataSource(dataSource); 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() { public boolean isMapperGenerateEnable() {
return mapperGenerateEnable; return mapperGenerateEnable;
} }

View File

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

View File

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

View File

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