mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fix: processor 退回到 v1.9.3
This commit is contained in:
parent
11127e1416
commit
302277609d
@ -26,35 +26,16 @@ MyBatis-Flex 使用了 APT(Annotation Processing Tool)技术,在项目编
|
||||
| processor.mapper.annotation | 开启 @Mapper 注解 | true/false | false |
|
||||
| processor.mapper.baseClass | 自定义 Mapper 的父类 | 全路径类名 | com.mybatisflex.core.BaseMapper |
|
||||
| processor.mapper.package | 自定义 Mapper 生成的包名 | 合法的包名 | ${entityPackage}.mapper |
|
||||
| processor.tableDef.package | 生成辅助类的包名 | 合法的包名 | ${entityPackage}.table |
|
||||
| processor.tableDef.propertiesNameStyle | 生成辅助类的字段风格 | upperCase, lowerCase<br />upperCamelCase, lowerCamelCase | upperCase |
|
||||
| processor.tableDef.instanceSuffix | 生成的表对应的变量后缀 | string | 空字符串 |
|
||||
| processor.tableDef.classSuffix | 生成的 TableDef 类的后缀 | string | TableDef |
|
||||
| processor.tableDef.ignoreEntitySuffixes | 过滤 Entity 后缀 | string | - |
|
||||
|
||||
对于示例中的包名表达式,说明如下:
|
||||
|
||||
1. 仅支持以下配置项使用表达式
|
||||
```text
|
||||
processor.allInTables.package
|
||||
processor.mapper.package
|
||||
processor.tableDef.package
|
||||
```
|
||||
2. `${entityPackage}`: 表示 Entity 类所在的包名
|
||||
3. `${entityPackage.parent}`: 表示 Entity 类所在的上一级包名
|
||||
4. `parent` 参数的数量没有限制,但如果超出了可能的层级,则会导致异常
|
||||
|
||||
**示例配置:**
|
||||
|
||||
假设 Example 类的全限定类名为 `com.mybatisflex.entity.Example`
|
||||
|
||||
配置内容如下:
|
||||
|
||||
```properties
|
||||
processor.allInTables.package=${entityPackage}.table
|
||||
processor.mapper.package=${entityPackage.parent}.mapper
|
||||
processor.tableDef.package=${entityPackage.parent.parent}.table
|
||||
```
|
||||
|
||||
生成类的全限定类名如下:
|
||||
|
||||
|
||||
@ -77,11 +77,6 @@ public enum ConfigurationKey {
|
||||
MAPPER_PACKAGE("processor.mapper.package", null),
|
||||
|
||||
|
||||
/**
|
||||
* 自定义 Class 生成的包名。
|
||||
*/
|
||||
TABLE_DEF_PACKAGE("processor.tableDef.package", null),
|
||||
|
||||
/**
|
||||
* 生成的 Class 的后缀。
|
||||
*/
|
||||
|
||||
@ -16,11 +16,6 @@
|
||||
|
||||
package com.mybatisflex.processor.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 字符串工具类。
|
||||
*
|
||||
@ -33,8 +28,6 @@ public class StrUtil {
|
||||
private StrUtil() {
|
||||
}
|
||||
|
||||
private static final Pattern PACKAGE_REGEX = Pattern.compile("(?<expression>\\$\\{entityPackage[.parent]*\\})(?<subPackage>.*)");
|
||||
|
||||
/**
|
||||
* com.mybatisflex.test.entity.Account -> Account
|
||||
*/
|
||||
@ -121,40 +114,6 @@ public class StrUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析包名表达式
|
||||
* <p>将{@code `${entityPackage}`}替换为实际实体包名, 表达式中如果存在一个{@code `.parent`}则缩减包名末尾的一位。</p>
|
||||
* <p>示例:{@code `entityClass = com.test1.test2`}<br>
|
||||
* 1. 对于{@code `packageStr = ${entityPackage}`}处理结果为 {@code `com.test1.test2`}<br>
|
||||
* 2. 对于{@code `packageStr = ${entityPackage.parent}`}处理结果为 {@code `com.test1`}<br>
|
||||
* 3. 对于{@code `packageStr = ${entityPackage.parent}.customize`}处理结果为 {@code `com.test1.customize`}
|
||||
* </p>
|
||||
*/
|
||||
public static String processPackageExpression(String entityClass, String packageStr) {
|
||||
String entityPackage = entityClass.substring(0, entityClass.lastIndexOf("."));
|
||||
Matcher matcher = PACKAGE_REGEX.matcher(packageStr);
|
||||
if (!matcher.find()) {
|
||||
return entityPackage;
|
||||
}
|
||||
String expression = matcher.group("expression");
|
||||
expression = expression.substring(2, expression.length() - 1);
|
||||
String subPackage = matcher.group("subPackage");
|
||||
List<String> entityPackageSplit = Arrays.asList(entityPackage.split("\\."));
|
||||
while (expression.contains(".parent")) {
|
||||
if (entityPackageSplit.size() == 0) {
|
||||
throw new RuntimeException("Expression [.parent] has exceeded the maximum limit.");
|
||||
}
|
||||
int index = expression.lastIndexOf(".parent");
|
||||
if (index != -1) {
|
||||
expression = expression.substring(0, index);
|
||||
entityPackageSplit = entityPackageSplit.subList(0, entityPackageSplit.size() - 1);
|
||||
}
|
||||
}
|
||||
expression = expression.replace("entityPackage", String.join(".", entityPackageSplit));
|
||||
return expression + subPackage;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isGetterMethod(String methodName, String property) {
|
||||
if (methodName.startsWith("get") && methodName.length() > 3) {
|
||||
return firstCharToUpperCase(property).concat("()").equals(methodName.substring(3));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user