稳定版本-0609
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.example.workutils.biz.batch;
|
||||
|
||||
import com.example.workutils.biz.mybatis.service.MyBatisExportService;
|
||||
import com.example.workutils.biz.mybatisexport.service.MyBatisExportService;
|
||||
import com.example.workutils.biz.scanner.service.ScannerService;
|
||||
import com.example.workutils.system.tool.Tool;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package com.example.workutils.biz.mybatis;
|
||||
package com.example.workutils.biz.mybatisexport;
|
||||
|
||||
import com.example.workutils.biz.mybatis.service.MyBatisExportService;
|
||||
import com.example.workutils.biz.mybatisexport.service.MyBatisExportService;
|
||||
import com.example.workutils.system.tool.Tool;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -30,7 +30,7 @@ public class MyBatisExportTool implements Tool {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "mybatis";
|
||||
return "mybatisexport";
|
||||
}
|
||||
|
||||
@Override
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package com.example.workutils.biz.mybatis.service;
|
||||
package com.example.workutils.biz.mybatisexport.service;
|
||||
|
||||
import com.example.workutils.biz.mybatis.service.model.MybatisTag;
|
||||
import com.example.workutils.biz.mybatisexport.service.model.MybatisTag;
|
||||
import com.example.workutils.biz.scanner.service.config.ScanConfig;
|
||||
import com.example.workutils.system.support.FileOperationService;
|
||||
import com.example.workutils.system.support.OutputService;
|
||||
@@ -202,8 +202,8 @@ public class MyBatisExportService {
|
||||
return false;
|
||||
}
|
||||
String sqlText = removeSqlComments(tag.getTagOriginalXmlText());
|
||||
for (String pattern : TABLE_PATTERNS) {
|
||||
Pattern p = Pattern.compile(pattern);
|
||||
for (String patternStr : TABLE_PATTERNS) {
|
||||
Pattern p = Pattern.compile(patternStr);
|
||||
Matcher m = p.matcher(sqlText);
|
||||
while (m.find()) {
|
||||
String tableName = m.group(2);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.example.workutils.biz.mybatis.service.model;
|
||||
package com.example.workutils.biz.mybatisexport.service.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package com.example.workutils.biz.mybatis;
|
||||
package com.example.workutils.biz.mybatisgenerator;
|
||||
|
||||
import com.example.workutils.biz.mybatis.service.generator.MyBatisGeneratorService;
|
||||
import com.example.workutils.biz.mybatisgenerator.service.generator.MyBatisGeneratorService;
|
||||
import com.example.workutils.system.tool.Tool;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -31,7 +31,7 @@ public class MyBatisGeneratorTool implements Tool {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "mybatis-generator";
|
||||
return "mybatisgenerator";
|
||||
}
|
||||
|
||||
@Override
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.example.workutils.biz.mybatis.service.generator;
|
||||
package com.example.workutils.biz.mybatisgenerator.service.generator;
|
||||
|
||||
import org.mybatis.generator.api.CommentGenerator;
|
||||
import org.mybatis.generator.api.IntrospectedColumn;
|
||||
@@ -215,4 +215,4 @@ public class CustomCommentGenerator implements CommentGenerator {
|
||||
public void addRootComment(XmlElement rootElement) {
|
||||
// 不添加注释
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
package com.example.workutils.biz.mybatis.service.generator;
|
||||
package com.example.workutils.biz.mybatisgenerator.service.generator;
|
||||
|
||||
import org.mybatis.generator.api.IntrospectedColumn;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
@@ -27,7 +27,6 @@ public class LombokPlugin extends PluginAdapter {
|
||||
*/
|
||||
@Override
|
||||
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
|
||||
// 添加 @Data 注解
|
||||
topLevelClass.addAnnotation("@Data");
|
||||
topLevelClass.addImportedType(DATA_ANNOTATION);
|
||||
return true;
|
||||
+2
-8
@@ -1,4 +1,4 @@
|
||||
package com.example.workutils.biz.mybatis.service.generator;
|
||||
package com.example.workutils.biz.mybatisgenerator.service.generator;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.generator.api.MyBatisGenerator;
|
||||
@@ -45,7 +45,6 @@ public class MyBatisGeneratorService {
|
||||
* @return 生成结果信息
|
||||
*/
|
||||
public String generateByPattern(String pattern, boolean overwrite) throws Exception {
|
||||
// 查询数据库中匹配通配符的表
|
||||
List<String> matchedTables = queryTablesByPattern(pattern);
|
||||
|
||||
if (matchedTables.isEmpty()) {
|
||||
@@ -70,11 +69,9 @@ public class MyBatisGeneratorService {
|
||||
String username = props.getProperty("db_username");
|
||||
String password = props.getProperty("db_password");
|
||||
|
||||
// 从URL中提取数据库名
|
||||
String dbName = extractDatabaseName(url);
|
||||
|
||||
try (Connection conn = DriverManager.getConnection(url, username, password)) {
|
||||
// 查询匹配的表名
|
||||
String sql = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME LIKE ?";
|
||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setString(1, dbName);
|
||||
@@ -124,7 +121,6 @@ public class MyBatisGeneratorService {
|
||||
* 从JDBC URL中提取数据库名
|
||||
*/
|
||||
private String extractDatabaseName(String url) {
|
||||
// jdbc:mysql://localhost:3306/disburse?xxx -> disburse
|
||||
int start = url.lastIndexOf('/');
|
||||
int end = url.indexOf('?', start);
|
||||
if (end == -1) {
|
||||
@@ -187,14 +183,12 @@ public class MyBatisGeneratorService {
|
||||
content = sb.toString();
|
||||
}
|
||||
|
||||
// 移除原有的 table 元素
|
||||
java.util.regex.Pattern tablePattern = java.util.regex.Pattern.compile(
|
||||
"<table[^>]*/>|<table[^>]*>.*?</table>",
|
||||
java.util.regex.Pattern.DOTALL
|
||||
);
|
||||
content = tablePattern.matcher(content).replaceAll("");
|
||||
|
||||
// 构建新的 table 元素
|
||||
StringBuilder tableElements = new StringBuilder();
|
||||
for (String tableName : tableNames) {
|
||||
tableElements.append(" <table schema=\"\" tableName=\"")
|
||||
@@ -281,4 +275,4 @@ public class MyBatisGeneratorService {
|
||||
public String getSqlMapperPackage() {
|
||||
return getConfigurationProperties().getProperty("sqlmapper_package", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -1,4 +1,4 @@
|
||||
package com.example.workutils.biz.mybatis.service.generator;
|
||||
package com.example.workutils.biz.mybatisgenerator.service.generator;
|
||||
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.PluginAdapter;
|
||||
@@ -24,31 +24,26 @@ public class SelectiveOnlyPlugin extends PluginAdapter {
|
||||
|
||||
@Override
|
||||
public boolean clientInsertMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
// 禁用 insert(全字段插入)
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clientInsertSelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
// 保留 insertSelective
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
// 禁用 updateByPrimaryKey(全字段更新)
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clientUpdateByPrimaryKeySelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
// 保留 updateByPrimaryKeySelective
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clientDeleteByPrimaryKeyMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
// 禁用 deleteByPrimaryKey(根据主键删除)
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,19 +51,16 @@ public class SelectiveOnlyPlugin extends PluginAdapter {
|
||||
|
||||
@Override
|
||||
public boolean sqlMapInsertElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
|
||||
// 禁用 insert XML元素(全字段插入)
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
|
||||
// 禁用 updateByPrimaryKey XML元素(全字段更新)
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sqlMapDeleteByPrimaryKeyElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
|
||||
// 禁用 deleteByPrimaryKey XML元素(根据主键删除)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user