代码生成修改 生成全参Dto
This commit is contained in:
parent
a4d9a0b003
commit
6c401cb38b
|
|
@ -28,7 +28,7 @@ public class Main {
|
|||
// String servicePackageName = "product";
|
||||
String packageName = "order";
|
||||
|
||||
String tableName = "tb_order_info";
|
||||
String tableName = "tb_cashier_cart";
|
||||
String author = "ww";
|
||||
|
||||
//配置数据源
|
||||
|
|
@ -51,6 +51,12 @@ public class Main {
|
|||
Generator serviceGenerator = new Generator(dataSource, serviceConfig);
|
||||
serviceConfig.setAuthor(author);
|
||||
serviceGenerator.generate();
|
||||
|
||||
//默认生成全参数DTO
|
||||
GlobalConfig dtoConfig = createDtoGlobalConfig(currentWorkingDirectory + "/cash-common/cash-common-service",
|
||||
basePackage + packageName, "tb", tableName);
|
||||
Generator dtoGenerator = new Generator(dataSource, dtoConfig);
|
||||
dtoGenerator.generate();
|
||||
}
|
||||
|
||||
public static GlobalConfig createGlobalConfigUseStyle(String projectPath, String packageName, String tablePrefix, String... tableNames) {
|
||||
|
|
@ -148,4 +154,32 @@ public class Main {
|
|||
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
public static GlobalConfig createDtoGlobalConfig(String projectPath, String packageName, String tablePrefix, String... tableNames) {
|
||||
//创建配置内容
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
||||
//设置根包
|
||||
globalConfig.getPackageConfig()
|
||||
.setEntityPackage(packageName + ".dto")
|
||||
.setSourceDir(projectPath + "/src/main/java")
|
||||
.setBasePackage(packageName);
|
||||
|
||||
//设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix(tablePrefix)
|
||||
.setGenerateTable(tableNames);
|
||||
globalConfig.setEntityTemplatePath("templates/entityDto.tpl");
|
||||
|
||||
globalConfig.getEntityConfig()
|
||||
.setClassSuffix("DTO")
|
||||
;
|
||||
|
||||
//设置生成 entity 并启用 Lombok
|
||||
globalConfig.enableEntity()
|
||||
.setWithLombok(true)
|
||||
.setJdkVersion(21);
|
||||
|
||||
return globalConfig;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,129 @@
|
|||
#set(withLombok = entityConfig.isWithLombok())
|
||||
#set(withSwagger = entityConfig.isWithSwagger())
|
||||
#set(swaggerVersion = entityConfig.getSwaggerVersion())
|
||||
#set(withActiveRecord = entityConfig.isWithActiveRecord())
|
||||
#set(jdkVersion = entityConfig.getJdkVersion())
|
||||
|
||||
package #(entityPackageName);
|
||||
|
||||
#for(importClass : table.buildImports(isBase))
|
||||
#if(!importClass.startsWith("com.mybatisflex.annotation"))
|
||||
import #(importClass);
|
||||
#end
|
||||
#end
|
||||
#for(column : table.columns)
|
||||
#if(column.propertySimpleType == "LocalDateTime")
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
#break
|
||||
#end
|
||||
#end
|
||||
#if(withActiveRecord)
|
||||
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;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
#end
|
||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#end
|
||||
#if(withLombok)
|
||||
#if(withActiveRecord)
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
#else
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
#if(entityConfig.getSuperClass(table))
|
||||
import lombok.EqualsAndHashCode;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* #(table.getComment()) 实体类。
|
||||
*
|
||||
* @author #(javadocConfig.getAuthor())
|
||||
* @since #(javadocConfig.getSince())
|
||||
*/
|
||||
#if(withLombok)
|
||||
#if(withActiveRecord)
|
||||
@Accessors(chain = true)
|
||||
@Data(staticConstructor = "create")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
#else
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
#if(entityConfig.getSuperClass(table))
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||
@ApiModel("#(table.getComment())")
|
||||
#end
|
||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||
@Schema(description = "#(table.getComment())")
|
||||
#end
|
||||
#end
|
||||
public class #(entityClassName)#if(withActiveRecord) extends Model<#(entityClassName)>#else#(table.buildExtends(isBase))#(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(hasText(comment))
|
||||
/**
|
||||
* #(comment)
|
||||
*/
|
||||
#end
|
||||
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||
@ApiModelProperty("#(column.comment)")
|
||||
#end
|
||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||
@Schema(description = "#(column.comment)")
|
||||
#end
|
||||
#if(column.propertySimpleType == "LocalDateTime")
|
||||
#set(isLocalDateTime = true)
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
#end
|
||||
private #(column.propertySimpleType) #(column.property)#if(hasText(column.propertyDefaultValue)) = #(column.propertyDefaultValue)#end;
|
||||
|
||||
#end
|
||||
#if(!withLombok)
|
||||
#if(withActiveRecord)
|
||||
public static #(entityClassName) create() {
|
||||
return new #(entityClassName)();
|
||||
}
|
||||
|
||||
#end
|
||||
#for(column: table.columns)
|
||||
public #(column.propertySimpleType) #(column.getterMethod())() {
|
||||
return #(column.property);
|
||||
}
|
||||
|
||||
#if(withActiveRecord)
|
||||
public #(entityClassName) #(column.setterMethod())(#(column.propertySimpleType) #(column.property)) {
|
||||
this.#(column.property) = #(column.property);
|
||||
return this;
|
||||
}
|
||||
#else
|
||||
public void #(column.setterMethod())(#(column.propertySimpleType) #(column.property)) {
|
||||
this.#(column.property) = #(column.property);
|
||||
}
|
||||
#end
|
||||
|
||||
#end
|
||||
#end}
|
||||
Loading…
Reference in New Issue