add custom BaseMapper class for codegen

This commit is contained in:
开源海哥 2023-04-17 17:16:43 +08:00
parent 90b04302b1
commit 83e6282069
5 changed files with 29 additions and 2 deletions

View File

@ -17,6 +17,7 @@ package com.mybatisflex.codegen.config;
import com.mybatisflex.codegen.template.EnjoyTemplate;
import com.mybatisflex.codegen.template.ITemplate;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.util.StringUtil;
import java.io.Serializable;
@ -63,6 +64,9 @@ public class GlobalConfig {
//mapper 的包名
private String mapperPackage;
//自定义 mapper 的父类
private Class<?> mapperSupperClass = BaseMapper.class;
//数据库表前缀多个前缀用英文逗号, 隔开
private String tablePrefix;
@ -205,6 +209,14 @@ public class GlobalConfig {
this.mapperPackage = mapperPackage;
}
public Class<?> getMapperSupperClass() {
return mapperSupperClass;
}
public void setMapperSupperClass(Class<?> mapperSupperClass) {
this.mapperSupperClass = mapperSupperClass;
}
public String getTablePrefix() {
return tablePrefix;
}

View File

@ -253,6 +253,14 @@ public class Table {
return tableAnnotation.append(")").toString();
}
public String buildMapperImport(){
return globalConfig.getMapperSupperClass().getName();
}
public String buildMapperName(){
return globalConfig.getMapperSupperClass().getSimpleName();
}
@Override
public String toString() {

View File

@ -1,8 +1,8 @@
package #(globalConfig.mapperPackage);
import com.mybatisflex.core.BaseMapper;
import #(table.buildMapperImport());
import #(globalConfig.entityPackage).#(table.buildEntityClassName());
public interface #(table.buildMapperClassName()) extends BaseMapper<#(table.buildEntityClassName())> {
public interface #(table.buildMapperClassName()) extends #(table.buildMapperName())<#(table.buildEntityClassName())> {
}

View File

@ -55,6 +55,7 @@ public class GeneratorTest {
//设置 mapper 类的包名
globalConfig.setMapperPackage("com.test.mapper");
globalConfig.setMapperSupperClass(MyBaseMapper.class);
TableConfig tableConfig = new TableConfig();

View File

@ -0,0 +1,6 @@
package com.mybatisflex.codegen.test;
import com.mybatisflex.core.BaseMapper;
public interface MyBaseMapper<T> extends BaseMapper<T> {
}