diff --git a/releases/tape-mybatis-generator-plugin-1.0-SNAPSHOT.jar b/releases/tape-mybatis-generator-plugin-1.0-SNAPSHOT.jar index 03bf3d5..c5c8c2f 100644 Binary files a/releases/tape-mybatis-generator-plugin-1.0-SNAPSHOT.jar and b/releases/tape-mybatis-generator-plugin-1.0-SNAPSHOT.jar differ diff --git a/src/main/java/com/iqudoo/framework/mybatis/TapeMybatisGeneratorPlugin.java b/src/main/java/com/iqudoo/framework/mybatis/TapeMybatisGeneratorPlugin.java index 781632d..f61dd64 100644 --- a/src/main/java/com/iqudoo/framework/mybatis/TapeMybatisGeneratorPlugin.java +++ b/src/main/java/com/iqudoo/framework/mybatis/TapeMybatisGeneratorPlugin.java @@ -56,48 +56,46 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter { } private int getIgnorePageSize(IntrospectedTable introspectedTable) { - try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String getIgnorePageSize = tableConfiguration.getProperty("ignorePageSize"); - if (getIgnorePageSize != null && !getIgnorePageSize.isEmpty()) { - int value = Integer.parseInt(getIgnorePageSize); - if (value > 0) { - return value; - } - } - } catch (Throwable ignored) { - } - return ignorePageSize; + return getTableInt(introspectedTable, "ignorePageSize", ignorePageSize); } public int getMaxPageSize(IntrospectedTable introspectedTable) { - try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String getMaxPageSize = tableConfiguration.getProperty("maxPageSize"); - if (getMaxPageSize != null && !getMaxPageSize.isEmpty()) { - int value = Integer.parseInt(getMaxPageSize); - if (value > 0) { - return value; - } - } - } catch (Throwable ignored) { - } - return maxPageSize; + return getTableInt(introspectedTable, "maxPageSize", maxPageSize); } public int getStartPageNum(IntrospectedTable introspectedTable) { + return getTableInt(introspectedTable, "startPageNum", startPageNum); + } + + // ====================== 统一 Table 属性获取(你全类都能用) ====================== + private String getTableProperty(IntrospectedTable introspectedTable, String propName, String defaultValue) { try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String getStartPageNum = tableConfiguration.getProperty("startPageNum"); - if (getStartPageNum != null && !getStartPageNum.isEmpty()) { - int value = Integer.parseInt(getStartPageNum); - if (value > 0) { - return value; - } + TableConfiguration tc = introspectedTable.getTableConfiguration(); + String v = tc.getProperty(propName); + if (StringUtility.stringHasValue(v)) { + return v.trim(); } - } catch (Throwable ignored) { + } catch (Exception ignored) { + } + return defaultValue; + } + + private boolean getTableBool(IntrospectedTable introspectedTable, String propName, boolean defaultValue) { + String v = getTableProperty(introspectedTable, propName, String.valueOf(defaultValue)); + try { + return Boolean.parseBoolean(v); + } catch (Exception e) { + return defaultValue; + } + } + + private int getTableInt(IntrospectedTable introspectedTable, String propName, int defaultValue) { + String v = getTableProperty(introspectedTable, propName, String.valueOf(defaultValue)); + try { + return Integer.parseInt(v); + } catch (Exception e) { + return defaultValue; } - return startPageNum; } @SuppressWarnings("DuplicatedCode") diff --git a/src/main/java/com/iqudoo/framework/mybatis/TapeRepositoryGeneratorPlugin.java b/src/main/java/com/iqudoo/framework/mybatis/TapeRepositoryGeneratorPlugin.java index 290cb44..2644e5c 100644 --- a/src/main/java/com/iqudoo/framework/mybatis/TapeRepositoryGeneratorPlugin.java +++ b/src/main/java/com/iqudoo/framework/mybatis/TapeRepositoryGeneratorPlugin.java @@ -52,9 +52,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter { targetProject = stringConfig("targetProject", targetProject); slowQueryLoggerTime = stringConfig("slowQueryLoggerTime", slowQueryLoggerTime); slowQueryLoggerLevel = stringConfig("slowQueryLoggerLevel", slowQueryLoggerLevel); - if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, slowQueryLoggerLevel)) { - slowQueryLoggerLevel = "error"; - } guidGeneratorClass = stringConfig("guidGeneratorClass", guidGeneratorClass); guidGeneratorCode = stringConfig("guidGeneratorCode", guidGeneratorCode); facadeRepositoryPackage = stringConfig("facadeRepositoryPackage", facadeRepositoryPackage); @@ -67,70 +64,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter { modelPackage = stringConfig("modelPackage", modelPackage); } - private boolean isChangeLogEnable(IntrospectedTable introspectedTable) { - String tableChangeLogEnable = changeLogEnable; - try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String getChangeLogEnable = tableConfiguration.getProperty("changeLogEnable"); - if (getChangeLogEnable != null && !getChangeLogEnable.isEmpty()) { - tableChangeLogEnable = getChangeLogEnable; - } - } catch (Throwable ignored) { - } - try { - boolean b = Boolean.parseBoolean(tableChangeLogEnable); - if (b) { - return true; - } - } catch (Throwable ignored) { - } - return false; - } - - private boolean isOptimisticLockEnable(IntrospectedTable introspectedTable) { - String tableOptimisticLockEnable = optimisticLockEnable; - try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String getOptimisticLockEnable = tableConfiguration.getProperty("optimisticLockEnable"); - if (getOptimisticLockEnable != null && !getOptimisticLockEnable.isEmpty()) { - tableOptimisticLockEnable = getOptimisticLockEnable; - } - } catch (Throwable ignored) { - } - try { - boolean b = Boolean.parseBoolean(tableOptimisticLockEnable); - if (b) { - return true; - } - } catch (Throwable ignored) { - } - return false; - } - - public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) { - try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel"); - if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) { - return tableSlowQueryLoggerLevel; - } - } catch (Throwable ignored) { - } - return slowQueryLoggerLevel; - } - - public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) { - try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime"); - if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) { - return tableSlowQueryLoggerTime; - } - } catch (Throwable ignored) { - } - return slowQueryLoggerTime; - } - private String stringConfig(String key, String defaultValue) { String v = properties.getProperty(key); if (StringUtility.stringHasValue(v)) { @@ -145,6 +78,48 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter { return defaultValue; } + private boolean isChangeLogEnable(IntrospectedTable introspectedTable) { + return getTableBool(introspectedTable, "changeLogEnable", Boolean.parseBoolean(changeLogEnable)); + } + + private boolean isOptimisticLockEnable(IntrospectedTable introspectedTable) { + return getTableBool(introspectedTable, "optimisticLockEnable", Boolean.parseBoolean(optimisticLockEnable)); + } + + private String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) { + String level = getTableProperty(introspectedTable, "slowQueryLoggerLevel", slowQueryLoggerLevel); + if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, level)) { + return "error"; + } + return level; + } + + private String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) { + return getTableProperty(introspectedTable, "slowQueryLoggerTime", slowQueryLoggerTime); + } + + // ====================== 统一 Table 属性获取(你全类都能用) ====================== + private String getTableProperty(IntrospectedTable introspectedTable, String propName, String defaultValue) { + try { + TableConfiguration tc = introspectedTable.getTableConfiguration(); + String v = tc.getProperty(propName); + if (StringUtility.stringHasValue(v)) { + return v.trim(); + } + } catch (Exception ignored) { + } + return defaultValue; + } + + private boolean getTableBool(IntrospectedTable introspectedTable, String propName, boolean defaultValue) { + String v = getTableProperty(introspectedTable, propName, String.valueOf(defaultValue)); + try { + return Boolean.parseBoolean(v); + } catch (Exception e) { + return defaultValue; + } + } + /** * 核心方法:视图表过滤 + 生成完整Repository代码 */ diff --git a/src/main/java/com/iqudoo/framework/mybatis/TapeRepoviewGeneratorPlugin.java b/src/main/java/com/iqudoo/framework/mybatis/TapeRepoviewGeneratorPlugin.java index e63abbe..453bb34 100644 --- a/src/main/java/com/iqudoo/framework/mybatis/TapeRepoviewGeneratorPlugin.java +++ b/src/main/java/com/iqudoo/framework/mybatis/TapeRepoviewGeneratorPlugin.java @@ -49,9 +49,6 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter { targetProject = stringConfig("targetProject", targetProject); slowQueryLoggerTime = stringConfig("slowQueryLoggerTime", slowQueryLoggerTime); slowQueryLoggerLevel = stringConfig("slowQueryLoggerLevel", slowQueryLoggerLevel); - if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, slowQueryLoggerLevel)) { - slowQueryLoggerLevel = "error"; - } facadeViewRepositoryPackage = stringConfig("facadeViewRepositoryPackage", facadeViewRepositoryPackage); domainViewRepositoryPackage = stringConfig("facadeViewRepositoryPackage", domainViewRepositoryPackage); mapperPackage = stringConfig("mapperPackage", mapperPackage); @@ -72,28 +69,29 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter { return defaultValue; } - public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) { - try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel"); - if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) { - return tableSlowQueryLoggerLevel; - } - } catch (Throwable ignored) { + private String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) { + String level = getTableProperty(introspectedTable, "slowQueryLoggerLevel", slowQueryLoggerLevel); + if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, level)) { + return "error"; } - return slowQueryLoggerLevel; + return level; } - public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) { + private String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) { + return getTableProperty(introspectedTable, "slowQueryLoggerTime", slowQueryLoggerTime); + } + + // ====================== 统一 Table 属性获取(你全类都能用) ====================== + private String getTableProperty(IntrospectedTable introspectedTable, String propName, String defaultValue) { try { - TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration(); - String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime"); - if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) { - return tableSlowQueryLoggerTime; + TableConfiguration tc = introspectedTable.getTableConfiguration(); + String v = tc.getProperty(propName); + if (StringUtility.stringHasValue(v)) { + return v.trim(); } - } catch (Throwable ignored) { + } catch (Exception ignored) { } - return slowQueryLoggerTime; + return defaultValue; } /** @@ -244,7 +242,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter { generateFindOneMethod(implClass, modelClassName, exampleClassName); generateGetListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns); generateCountMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName); - generateCountWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName); + generateCountWithPageMethod(implClass, exampleClassName); return implClass; } @@ -374,7 +372,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter { /** * 生成count方法 */ - private void generateCountWithPageMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) { + private void generateCountWithPageMethod(TopLevelClass implClass, String exampleClassName) { Method method = new Method("countWithPage"); method.addAnnotation("@Override"); method.setVisibility(JavaVisibility.PUBLIC);