|
@@ -15,19 +15,6 @@
|
|
|
*/
|
|
|
package com.baomidou.mybatisplus.generator.config.builder;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
-import com.baomidou.mybatisplus.generator.InjectionConfig;
|
|
|
-import com.baomidou.mybatisplus.generator.config.*;
|
|
|
-import com.baomidou.mybatisplus.generator.config.po.TableField;
|
|
|
-import com.baomidou.mybatisplus.generator.config.po.TableFill;
|
|
|
-import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|
|
-import com.baomidou.mybatisplus.generator.config.querys.H2Query;
|
|
|
-import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
|
|
-
|
|
|
import java.io.File;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
@@ -43,6 +30,27 @@ import java.util.Set;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.generator.InjectionConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.ConstVal;
|
|
|
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.IDbQuery;
|
|
|
+import com.baomidou.mybatisplus.generator.config.IKeyWordsHandler;
|
|
|
+import com.baomidou.mybatisplus.generator.config.INameConvert;
|
|
|
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.TemplateConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.po.TableField;
|
|
|
+import com.baomidou.mybatisplus.generator.config.po.TableFill;
|
|
|
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|
|
+import com.baomidou.mybatisplus.generator.config.querys.H2Query;
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
|
|
+
|
|
|
/**
|
|
|
* 配置汇总 传递给文件生成工具
|
|
|
*
|
|
@@ -110,7 +118,7 @@ public class ConfigBuilder {
|
|
|
/**
|
|
|
* 过滤正则
|
|
|
*/
|
|
|
- private static final Pattern REGX = Pattern.compile("[~!/@#$%^&*()-_=+\\\\|[{}];:\\'\\\",<.>/?]+");
|
|
|
+ private static final Pattern REGX = Pattern.compile("[~!/@#$%^&*()-_=+\\\\|[{}];:'\",<.>?]+");
|
|
|
|
|
|
/**
|
|
|
* 在构造器中处理配置
|
|
@@ -477,49 +485,49 @@ public class ConfigBuilder {
|
|
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql.toString());
|
|
|
ResultSet results = preparedStatement.executeQuery()) {
|
|
|
while (results.next()) {
|
|
|
- String tableName = results.getString(dbQuery.tableName());
|
|
|
- if (StringUtils.isNotBlank(tableName)) {
|
|
|
- tableInfo = new TableInfo();
|
|
|
- tableInfo.setName(tableName);
|
|
|
- String commentColumn = dbQuery.tableComment();
|
|
|
- if (StringUtils.isNotBlank(commentColumn)) {
|
|
|
- String tableComment = results.getString(commentColumn);
|
|
|
- if (config.isSkipView() && "VIEW".equals(tableComment)) {
|
|
|
- // 跳过视图
|
|
|
- continue;
|
|
|
- }
|
|
|
- tableInfo.setComment(formatComment(tableComment));
|
|
|
+ final String tableName = results.getString(dbQuery.tableName());
|
|
|
+ if (StringUtils.isBlank(tableName)) {
|
|
|
+ System.err.println("当前数据库为空!!!");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ tableInfo = new TableInfo();
|
|
|
+ tableInfo.setName(tableName);
|
|
|
+ String commentColumn = dbQuery.tableComment();
|
|
|
+ if (StringUtils.isNotBlank(commentColumn)) {
|
|
|
+ String tableComment = results.getString(commentColumn);
|
|
|
+ if (config.isSkipView() && "VIEW".equals(tableComment)) {
|
|
|
+ // 跳过视图
|
|
|
+ continue;
|
|
|
}
|
|
|
+ tableInfo.setComment(formatComment(tableComment));
|
|
|
+ }
|
|
|
|
|
|
- if (isInclude) {
|
|
|
- for (String includeTable : config.getInclude()) {
|
|
|
- // 忽略大小写等于 或 正则 true
|
|
|
- if (tableNameMatches(includeTable, tableName)) {
|
|
|
- includeTableList.add(tableInfo);
|
|
|
- } else {
|
|
|
- //过滤正则表名
|
|
|
- if (!REGX.matcher(includeTable).find()) {
|
|
|
- notExistTables.add(includeTable);
|
|
|
- }
|
|
|
+ if (isInclude) {
|
|
|
+ for (String includeTable : config.getInclude()) {
|
|
|
+ // 忽略大小写等于 或 正则 true
|
|
|
+ if (tableNameMatches(includeTable, tableName)) {
|
|
|
+ includeTableList.add(tableInfo);
|
|
|
+ } else {
|
|
|
+ //过滤正则表名
|
|
|
+ if (!REGX.matcher(includeTable).find()) {
|
|
|
+ notExistTables.add(includeTable);
|
|
|
}
|
|
|
}
|
|
|
- } else if (isExclude) {
|
|
|
- for (String excludeTable : config.getExclude()) {
|
|
|
- // 忽略大小写等于 或 正则 true
|
|
|
- if (tableNameMatches(excludeTable, tableName)) {
|
|
|
- excludeTableList.add(tableInfo);
|
|
|
- } else {
|
|
|
- //过滤正则表名
|
|
|
- if (!REGX.matcher(excludeTable).find()) {
|
|
|
- notExistTables.add(excludeTable);
|
|
|
- }
|
|
|
+ }
|
|
|
+ } else if (isExclude) {
|
|
|
+ for (String excludeTable : config.getExclude()) {
|
|
|
+ // 忽略大小写等于 或 正则 true
|
|
|
+ if (tableNameMatches(excludeTable, tableName)) {
|
|
|
+ excludeTableList.add(tableInfo);
|
|
|
+ } else {
|
|
|
+ //过滤正则表名
|
|
|
+ if (!REGX.matcher(excludeTable).find()) {
|
|
|
+ notExistTables.add(excludeTable);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- tableList.add(tableInfo);
|
|
|
- } else {
|
|
|
- System.err.println("当前数据库为空!!!");
|
|
|
}
|
|
|
+ tableList.add(tableInfo);
|
|
|
}
|
|
|
}
|
|
|
// 将已经存在的表移除,获取配置中数据库不存在的表
|
|
@@ -714,7 +722,7 @@ public class ConfigBuilder {
|
|
|
* @return 连接后的包名
|
|
|
*/
|
|
|
private String joinPackage(String parent, String subPackage) {
|
|
|
- return StringUtils.isBlank(parent) ? subPackage : parent + StringPool.DOT + subPackage;
|
|
|
+ return StringUtils.isBlank(parent) ? subPackage : (parent + StringPool.DOT + subPackage);
|
|
|
}
|
|
|
|
|
|
|