mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
close #I6VQ5W
This commit is contained in:
parent
f4cbf0c396
commit
11764532b5
@ -19,6 +19,7 @@ import com.mybatisflex.codegen.template.EnjoyTemplate;
|
||||
import com.mybatisflex.codegen.template.ITemplate;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -38,6 +39,12 @@ public class GlobalConfig {
|
||||
//entity 类的后缀
|
||||
private String entityClassSuffix;
|
||||
|
||||
//entity 类的父类,可以自定义一些 BaseEntity 类
|
||||
private Class<?> entitySupperClass;
|
||||
|
||||
//entity 默认实现的接口
|
||||
private Class<?>[] entityInterfaces = {Serializable.class};
|
||||
|
||||
//entity 是否使用 Lombok
|
||||
private boolean entityWithLombok = false;
|
||||
|
||||
@ -128,6 +135,22 @@ public class GlobalConfig {
|
||||
this.entityClassSuffix = entityClassSuffix;
|
||||
}
|
||||
|
||||
public Class<?> getEntitySupperClass() {
|
||||
return entitySupperClass;
|
||||
}
|
||||
|
||||
public void setEntitySupperClass(Class<?> entitySupperClass) {
|
||||
this.entitySupperClass = entitySupperClass;
|
||||
}
|
||||
|
||||
public Class<?>[] getEntityInterfaces() {
|
||||
return entityInterfaces;
|
||||
}
|
||||
|
||||
public void setEntityInterfaces(Class<?>[] entityInterfaces) {
|
||||
this.entityInterfaces = entityInterfaces;
|
||||
}
|
||||
|
||||
public boolean isEntityWithLombok() {
|
||||
return entityWithLombok;
|
||||
}
|
||||
|
||||
@ -129,6 +129,16 @@ public class Table {
|
||||
imports.add("lombok.NoArgsConstructor");
|
||||
}
|
||||
|
||||
if (globalConfig.getEntitySupperClass() != null) {
|
||||
imports.add(globalConfig.getEntitySupperClass().getName());
|
||||
}
|
||||
|
||||
if (globalConfig.getEntityInterfaces() != null) {
|
||||
for (Class<?> entityInterface : globalConfig.getEntityInterfaces()) {
|
||||
imports.add(entityInterface.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (tableConfig != null) {
|
||||
if (tableConfig.getInsertListenerClass() != null) {
|
||||
imports.add(tableConfig.getInsertListenerClass().getName());
|
||||
@ -168,6 +178,24 @@ public class Table {
|
||||
+ globalConfig.getEntityClassSuffix();
|
||||
}
|
||||
|
||||
public String buildExtends() {
|
||||
if (globalConfig.getEntitySupperClass() != null) {
|
||||
return " extends " + globalConfig.getEntitySupperClass().getSimpleName();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String buildImplements() {
|
||||
Class<?>[] entityInterfaces = globalConfig.getEntityInterfaces();
|
||||
if (entityInterfaces != null && entityInterfaces.length > 0) {
|
||||
return " implements " + StringUtil.join(", ", Arrays.stream(entityInterfaces)
|
||||
.map(Class::getSimpleName).collect(Collectors.toList()));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String buildMapperClassName() {
|
||||
String entityJavaFileName = name;
|
||||
|
||||
@ -6,7 +6,7 @@ import #(importClass);
|
||||
|
||||
|
||||
#(table.buildTableAnnotation())
|
||||
public class #(table.buildEntityClassName()) {
|
||||
public class #(table.buildEntityClassName())#(table.buildExtends())#(table.buildImplements()) {
|
||||
|
||||
#for(column: table.columns) #(column.buildAnnotations())
|
||||
private #(column.propertySimpleType) #(column.property);
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package com.mybatisflex.codegen.test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class BaseEntity {
|
||||
private Date createTime;
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@ -38,6 +38,8 @@ public class GeneratorTest {
|
||||
// globalConfig.setTablePrefix("tb_");
|
||||
// globalConfig.setEntityWithLombok(true);
|
||||
|
||||
globalConfig.setEntitySupperClass(BaseEntity.class);
|
||||
|
||||
//设置只生成哪些表
|
||||
globalConfig.addGenerateTable("tb_account", "account_session");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user