mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fix java代码生成器base类缺少import;feat kotlin代码生成器支持withBaseClass模式
This commit is contained in:
parent
74b6185f1f
commit
b22fcf75e7
@ -364,11 +364,11 @@ public class Table {
|
||||
/**
|
||||
* 构建 extends 继承。
|
||||
*/
|
||||
public String buildExtends() {
|
||||
public String buildExtends(boolean isBase) {
|
||||
EntityConfig entityConfig = globalConfig.getEntityConfig();
|
||||
Class<?> superClass = entityConfig.getSuperClass(this);
|
||||
if (superClass != null) {
|
||||
return " extends " + superClass.getSimpleName()+(entityConfig.isSuperClassGenericity()?("<"+buildEntityClassName()+">"):"");
|
||||
return " extends " + superClass.getSimpleName()+(entityConfig.isSuperClassGenericity()?("<"+buildEntityClassName()+(isBase?entityConfig.getWithBaseClassSuffix():"")+">"):"");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
@ -389,14 +389,14 @@ public class Table {
|
||||
/**
|
||||
* 构建 kt 继承
|
||||
*/
|
||||
public String buildKtExtends(){
|
||||
public String buildKtExtends(boolean isBase){
|
||||
EntityConfig entityConfig = globalConfig.getEntityConfig();
|
||||
Class<?> superClass = entityConfig.getSuperClass(this);
|
||||
List<String> s = new ArrayList<>();
|
||||
if (superClass != null) {
|
||||
String name = superClass.getSimpleName();
|
||||
if (entityConfig.isSuperClassGenericity()){
|
||||
name+="<"+buildEntityClassName()+">";
|
||||
name+="<"+buildEntityClassName()+(isBase?entityConfig.getWithBaseClassSuffix():"")+">";
|
||||
}
|
||||
name+="()";
|
||||
s.add(name);
|
||||
|
||||
@ -38,6 +38,7 @@ public class EntityGenerator implements IGenerator {
|
||||
protected String templatePath;
|
||||
|
||||
protected String entityWithBaseTemplatePath = "/templates/enjoy/entityWithBase.tpl";
|
||||
protected String ktEntityWithBaseTemplatePath = "/templates/enjoy/entityWithBase.kotlin.tpl";
|
||||
|
||||
|
||||
public EntityGenerator() {
|
||||
@ -98,11 +99,12 @@ public class EntityGenerator implements IGenerator {
|
||||
// 开启生成 baseClass
|
||||
if (entityConfig.isWithBaseClassEnable()) {
|
||||
if (globalConfig.getFileType() == GlobalConfig.FileType.KOTLIN) {
|
||||
throw new UnsupportedOperationException("暂不支持 Kotlin 生成 WithBaseClass 模式。");
|
||||
// throw new UnsupportedOperationException("暂不支持 Kotlin 生成 WithBaseClass 模式。");
|
||||
templatePath = this.ktEntityWithBaseTemplatePath;
|
||||
}else{
|
||||
templatePath = this.entityWithBaseTemplatePath;
|
||||
}
|
||||
|
||||
templatePath = this.entityWithBaseTemplatePath;
|
||||
|
||||
String baseClassName = table.buildEntityClassName() + entityConfig.getWithBaseClassSuffix();
|
||||
params.put("baseClassName", baseClassName);
|
||||
|
||||
@ -136,7 +138,7 @@ public class EntityGenerator implements IGenerator {
|
||||
|
||||
String baseEntityClassName = table.buildEntityClassName() + entityConfig.getWithBaseClassSuffix();
|
||||
|
||||
File baseEntityJavaFile = new File(sourceDir, baseEntityPackagePath + "/" + baseEntityClassName + ".java");
|
||||
File baseEntityJavaFile = new File(sourceDir, baseEntityPackagePath + "/" + baseEntityClassName + globalConfig.getFileType());
|
||||
|
||||
|
||||
// 排除忽略列
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#set(withSwagger = entityConfig.isWithSwagger())
|
||||
#set(withActiveRecord = entityConfig.isWithActiveRecord())
|
||||
|
||||
package #(entityPackageName);
|
||||
package #(entityPackageName)
|
||||
|
||||
#for(importClass : table.buildImports(isBase))
|
||||
import #(importClass)
|
||||
@ -18,6 +18,7 @@ import io.swagger.annotations.ApiModelProperty
|
||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
#end
|
||||
#if(!isBase)
|
||||
/**
|
||||
* #(table.getComment()) 实体类。
|
||||
*
|
||||
@ -25,7 +26,8 @@ import io.swagger.v3.oas.annotations.media.Schema
|
||||
* @since #(javadocConfig.getSince())
|
||||
*/
|
||||
#(table.buildTableAnnotation())
|
||||
class #(entityClassName) #if(withActiveRecord) : Model<#(entityClassName)>()#else#(table.buildKtExtends())#end {
|
||||
#end
|
||||
#if(isBase)open #end class #(entityClassName) #if(withActiveRecord) : Model<#(entityClassName)>()#else#(table.buildKtExtends(isBase))#end {
|
||||
#for(column : table.columns)
|
||||
#set(comment = javadocConfig.formatColumnComment(column.comment))
|
||||
#if(isNotBlank(comment))
|
||||
@ -43,7 +45,7 @@ class #(entityClassName) #if(withActiveRecord) : Model<#(entityClassName)>()#els
|
||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||
@Schema(description = "#(column.comment)")
|
||||
#end
|
||||
var #(column.property): #(column.propertySimpleType)? = #if(isNotBlank(column.propertyDefaultValue)) = #(column.propertyDefaultValue)#else null#end
|
||||
#if(isBase)open #end var #(column.property): #(column.propertySimpleType)? = #if(isNotBlank(column.propertyDefaultValue)) = #(column.propertyDefaultValue)#else null#end
|
||||
|
||||
#end
|
||||
}
|
||||
|
||||
@ -12,6 +12,10 @@ import #(importClass);
|
||||
import com.mybatisflex.core.activerecord.Model;
|
||||
#end
|
||||
|
||||
#if(jdkVersion >= 14)
|
||||
import java.io.Serial;
|
||||
#end
|
||||
|
||||
#if(!isBase)
|
||||
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||
import io.swagger.annotations.ApiModel;
|
||||
@ -35,9 +39,6 @@ import lombok.EqualsAndHashCode;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if(jdkVersion >= 14)
|
||||
import java.io.Serial;
|
||||
#end
|
||||
|
||||
/**
|
||||
* #(table.getComment()) 实体类。
|
||||
@ -67,7 +68,7 @@ import java.io.Serial;
|
||||
@Schema(description = "#(table.getComment())")
|
||||
#end
|
||||
#(table.buildTableAnnotation()) #end
|
||||
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(isBase))#(table.buildImplements())#end {
|
||||
|
||||
#if(jdkVersion >= 14)
|
||||
@Serial
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
#set(withSwagger = entityConfig.isWithSwagger())
|
||||
#set(withActiveRecord = entityConfig.isWithActiveRecord())
|
||||
|
||||
package #(entityPackageName)
|
||||
|
||||
#for(importClass : table.buildImports(isBase))
|
||||
import #(importClass)
|
||||
#end
|
||||
import #(baseClassPackage).#(baseClassName);
|
||||
|
||||
#if(withActiveRecord)
|
||||
import com.mybatisflex.core.activerecord.Model
|
||||
#end
|
||||
|
||||
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||
import io.swagger.annotations.ApiModel
|
||||
import io.swagger.annotations.ApiModelProperty
|
||||
#end
|
||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
#end
|
||||
/**
|
||||
* #(table.getComment()) 实体类。
|
||||
*
|
||||
* @author #(javadocConfig.getAuthor())
|
||||
* @since #(javadocConfig.getSince())
|
||||
*/
|
||||
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||
@ApiModel("#(table.getComment())")
|
||||
#end
|
||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||
@Schema(description = "#(table.getComment())")
|
||||
#end
|
||||
#if(!isBase)#(table.buildTableAnnotation())#end
|
||||
class #(entityClassName) : #(baseClassName)()
|
||||
Loading…
x
Reference in New Issue
Block a user