优化:不依赖表前缀判断是否为视图
This commit is contained in:
@@ -170,6 +170,21 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
||||
);
|
||||
FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByOffsetRows);
|
||||
|
||||
Method setLimitByOffsetOnly = ElementTools.generateMethod(
|
||||
"limitOffset",
|
||||
JavaVisibility.PUBLIC,
|
||||
topLevelClass.getType(),
|
||||
new Parameter(integerType, "offset"),
|
||||
new Parameter(integerType, "rows")
|
||||
);
|
||||
setLimitByOffsetOnly = ElementTools.generateMethodBody(
|
||||
setLimitByOffsetOnly,
|
||||
"this.offset = offset;",
|
||||
"this.rows = 999999999;",
|
||||
"return this;"
|
||||
);
|
||||
FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByOffsetOnly);
|
||||
|
||||
Method usePage = ElementTools.generateMethod(
|
||||
"usePage",
|
||||
JavaVisibility.PUBLIC,
|
||||
@@ -402,13 +417,13 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
||||
// ============================================ selectPrimaryKeyByExample ==========================================
|
||||
|
||||
@Override
|
||||
public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
public boolean clientGenerated(Interface interfaceObj, IntrospectedTable introspectedTable) {
|
||||
if (introspectedTable.getTargetRuntime() != IntrospectedTable.TargetRuntime.MYBATIS3) {
|
||||
return super.clientGenerated(interfaze, introspectedTable);
|
||||
return super.clientGenerated(interfaceObj, introspectedTable);
|
||||
}
|
||||
addBatchInsertClientMethod(interfaze, introspectedTable);
|
||||
addBatchInsertClientMethod(interfaceObj, introspectedTable);
|
||||
if (introspectedTable.getPrimaryKeyColumns().size() <= 0) {
|
||||
return super.clientGenerated(interfaze, introspectedTable);
|
||||
return super.clientGenerated(interfaceObj, introspectedTable);
|
||||
}
|
||||
// 获取主键列类型
|
||||
FullyQualifiedJavaType primaryType = introspectedTable.getPrimaryKeyColumns().get(0)
|
||||
@@ -424,9 +439,9 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
||||
method.setVisibility(JavaVisibility.PUBLIC);
|
||||
method.setReturnType(returnType);
|
||||
method.addParameter(new Parameter(exampleType, "example"));
|
||||
interfaze.addMethod(method);
|
||||
interfaceObj.addMethod(method);
|
||||
|
||||
return super.clientGenerated(interfaze, introspectedTable);
|
||||
return super.clientGenerated(interfaceObj, introspectedTable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
||||
private String modelPackage = "com.iqudoo.platform.application.database.model";
|
||||
private String mapperPackage = "com.iqudoo.platform.application.database.mapper";
|
||||
private String targetProject = "src/main/java";
|
||||
private String viewKeyWords = "VIEW_,V_";
|
||||
|
||||
// 1.4.1版本专用:Java格式化器
|
||||
private JavaFormatter javaFormatter;
|
||||
@@ -59,10 +58,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
||||
modelPackage = stringConfig("modelPackage", modelPackage);
|
||||
mapperPackage = stringConfig("mapperPackage", mapperPackage);
|
||||
targetProject = stringConfig("targetProject", targetProject);
|
||||
viewKeyWords = stringConfig("viewKeyWords", viewKeyWords);
|
||||
if (StringUtility.stringHasValue(viewKeyWords)) {
|
||||
viewKeyWords = viewKeyWords.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
private String stringConfig(String key, String defaultValue) {
|
||||
@@ -87,8 +82,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
||||
List<GeneratedJavaFile> generatedJavaFiles = new ArrayList<>();
|
||||
|
||||
// 视图表过滤逻辑
|
||||
String tableName = introspectedTable.getFullyQualifiedTable().getIntrospectedTableName().toUpperCase();
|
||||
if (isViewTable(tableName)) {
|
||||
if (ElementTools.isViewTable(introspectedTable)) {
|
||||
return generatedJavaFiles;
|
||||
}
|
||||
|
||||
@@ -135,18 +129,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
||||
return generatedJavaFiles;
|
||||
}
|
||||
|
||||
private boolean isViewTable(String tableName) {
|
||||
if (StringUtility.stringHasValue(viewKeyWords)) {
|
||||
String[] keywords = viewKeyWords.split(",");
|
||||
for (String keyword : keywords) {
|
||||
if (tableName.contains(keyword.trim().toUpperCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心修改:生成Repository接口(手动添加所有方法,无继承,匹配指定格式)
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,6 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
||||
private String modelPackage = "com.iqudoo.platform.application.database.model";
|
||||
private String mapperPackage = "com.iqudoo.platform.application.database.mapper";
|
||||
private String targetProject = "src/main/java";
|
||||
private String viewKeyWords = "VIEW_,V_";
|
||||
|
||||
// 1.4.1版本专用格式化器
|
||||
private JavaFormatter javaFormatter;
|
||||
@@ -56,10 +55,6 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
||||
modelPackage = stringConfig("modelPackage", modelPackage);
|
||||
mapperPackage = stringConfig("mapperPackage", mapperPackage);
|
||||
targetProject = stringConfig("targetProject", targetProject);
|
||||
viewKeyWords = stringConfig("viewKeyWords", viewKeyWords);
|
||||
if (StringUtility.stringHasValue(viewKeyWords)) {
|
||||
viewKeyWords = viewKeyWords.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
private String stringConfig(String key, String defaultValue) {
|
||||
@@ -82,13 +77,10 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
||||
@Override
|
||||
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
|
||||
List<GeneratedJavaFile> generatedJavaFiles = new ArrayList<>();
|
||||
|
||||
// 仅处理视图表,非视图表直接返回
|
||||
String tableName = introspectedTable.getFullyQualifiedTable().getIntrospectedTableName().toUpperCase();
|
||||
if (!isViewTable(tableName)) {
|
||||
if (!ElementTools.isViewTable(introspectedTable)) {
|
||||
return generatedJavaFiles;
|
||||
}
|
||||
|
||||
// 1. 获取视图表元数据
|
||||
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
|
||||
String exampleClassName = domainObjectName + "Example";
|
||||
@@ -132,22 +124,6 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
||||
return generatedJavaFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为视图表(关键字匹配 + MBG原生视图配置)
|
||||
*/
|
||||
private boolean isViewTable(String tableName) {
|
||||
// 关键字匹配
|
||||
if (StringUtility.stringHasValue(viewKeyWords)) {
|
||||
String[] keywords = viewKeyWords.split(",");
|
||||
for (String keyword : keywords) {
|
||||
if (tableName.contains(keyword.trim().toUpperCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心修改:生成视图Repo接口(移除继承,手动添加指定方法)
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,17 @@ import static org.mybatis.generator.internal.util.messages.Messages.getString;
|
||||
@SuppressWarnings("unused")
|
||||
public class ElementTools {
|
||||
|
||||
/**
|
||||
* 判断IntrospectedTable是否代表数据库视图
|
||||
*
|
||||
* @param introspectedTable MBG内省表对象
|
||||
* @return true=视图,false=普通表/其他类型
|
||||
*/
|
||||
public static boolean isViewTable(IntrospectedTable introspectedTable) {
|
||||
String tableType = introspectedTable.getTableType();
|
||||
return "VIEW".equals(tableType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测数据表是否含有BLOB列数据
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user