mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
add custom BaseMapper class for codegen
This commit is contained in:
parent
90b04302b1
commit
83e6282069
@ -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;
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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())> {
|
||||
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ public class GeneratorTest {
|
||||
|
||||
//设置 mapper 类的包名
|
||||
globalConfig.setMapperPackage("com.test.mapper");
|
||||
globalConfig.setMapperSupperClass(MyBaseMapper.class);
|
||||
|
||||
|
||||
TableConfig tableConfig = new TableConfig();
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
package com.mybatisflex.codegen.test;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
|
||||
public interface MyBaseMapper<T> extends BaseMapper<T> {
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user