mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
feat: add apt config "processor.tablesDefSuffix" close #I76Y46 #I78GMC #43
This commit is contained in:
parent
4b1ddae7bd
commit
dc39e6083b
@ -24,6 +24,7 @@ MyBatis-Flex 使用了 APT(Annotation Processing Tool)技术,在项目编
|
||||
| processor.baseMapperClass | 自定义 Mapper 的父类 | 全路径类名 | com.mybatisflex.core.BaseMapper |
|
||||
| processor.mappersPackage | 自定义 Mapper 生成的包名 | 合法的包名 | ${entityPackage}.mapper |
|
||||
| processor.tablesNameStyle | 生成辅助类的字段风格 | upperCase, lowerCase<br />upperCamelCase, lowerCamelCase | upperCase |
|
||||
| processor.tablesDefSuffix | 生成的表对应的变量后缀 | string | 空字符串 |
|
||||
| processor.entity.ignoreSuffixes | 过滤 Entity 后缀 | string | - |
|
||||
|
||||
|
||||
|
||||
@ -156,6 +156,9 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
||||
//upperCase, lowerCase, upperCamelCase, lowerCamelCase
|
||||
String tablesNameStyle = props.getProperties().getProperty("processor.tablesNameStyle", "upperCase");
|
||||
|
||||
//包名对应的变量后缀
|
||||
String tablesDefSuffix = props.getProperties().getProperty("processor.tablesDefSuffix", "");
|
||||
|
||||
String[] entityIgnoreSuffixes = props.getProperties().getProperty("processor.entity.ignoreSuffixes", "").split(",");
|
||||
|
||||
|
||||
@ -207,13 +210,15 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
if (allInTables) {
|
||||
String content = buildTablesClass(entitySimpleName, schema, tableName, propertyAndColumns, defaultColumns, tablesNameStyle, null, allInTables);
|
||||
String content = buildTablesClass(entitySimpleName, schema, tableName, propertyAndColumns, defaultColumns, tablesNameStyle
|
||||
, tablesDefSuffix, null, allInTables);
|
||||
tablesContent.append(content);
|
||||
}
|
||||
//每一个 entity 生成一个独立的文件
|
||||
else {
|
||||
String realGenPackage = genTablesPackage == null || genTablesPackage.trim().length() == 0 ? guessPackage.toString() : genTablesPackage;
|
||||
String content = buildTablesClass(entitySimpleName, schema, tableName, propertyAndColumns, defaultColumns, tablesNameStyle, realGenPackage, allInTables);
|
||||
String content = buildTablesClass(entitySimpleName, schema, tableName, propertyAndColumns, defaultColumns, tablesNameStyle
|
||||
, tablesDefSuffix, realGenPackage, allInTables);
|
||||
genClass(genPath, realGenPackage, entitySimpleName + "TableDef", content);
|
||||
}
|
||||
|
||||
@ -332,13 +337,14 @@ public class QueryEntityProcessor extends AbstractProcessor {
|
||||
|
||||
|
||||
private String buildTablesClass(String entityClass, String schema, String tableName, Map<String, String> propertyAndColumns
|
||||
, List<String> defaultColumns, String tablesNameStyle, String realGenPackage, boolean allInTables) {
|
||||
, List<String> defaultColumns, String tablesNameStyle, String tablesDefSuffix, String realGenPackage, boolean allInTables) {
|
||||
|
||||
// tableDefTemplate = " public static final @entityClassTableDef @tableField = new @entityClassTableDef(\"@tableName\");\n";
|
||||
|
||||
String tableDef = tableDefTemplate.replace("@entityClass", entityClass)
|
||||
.replace("@schema", schema)
|
||||
.replace("@tableField", buildName(entityClass, tablesNameStyle))
|
||||
.replace("@tableField", buildName(entityClass, tablesNameStyle)
|
||||
+ (tablesDefSuffix != null ? tablesDefSuffix.trim() : ""))
|
||||
.replace("@tableName", tableName);
|
||||
|
||||
|
||||
|
||||
@ -1 +1,3 @@
|
||||
processor.mappersGenerateEnable = true
|
||||
processor.tablesNameStyle = lowerCase
|
||||
processor.tablesDefSuffix = Def
|
||||
|
||||
@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT;
|
||||
import static com.mybatisflex.test.model.table.AccountTableDef.accountDef;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = AppConfig.class)
|
||||
@ -33,7 +33,7 @@ public class AccountTest implements WithAssertions {
|
||||
@Test
|
||||
public void testSelectByQuery() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(ACCOUNT.AGE.eq(18));
|
||||
.where(accountDef.age.eq(18));
|
||||
List<Account> accounts = accountMapper.selectListByQuery(queryWrapper);
|
||||
assertThat(accounts.size()).isEqualTo(1);
|
||||
assertThat(accounts.get(0).getAge()).isEqualTo(18);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user