mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
feat: 同步 APT 与 代码生成器 的配置。
This commit is contained in:
parent
45b2308cd6
commit
1e688d93e2
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.mybatisflex.codegen.config;
|
||||
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 生成 TableDef 的配置。
|
||||
*
|
||||
@ -39,6 +41,30 @@ public class TableDefConfig {
|
||||
*/
|
||||
private boolean overwriteEnable;
|
||||
|
||||
/**
|
||||
* 生成辅助类的字段风格。
|
||||
*/
|
||||
private NameStyle propertiesNameStyle = NameStyle.UPPER_CASE;
|
||||
|
||||
/**
|
||||
* 生成的表对应的变量后缀。
|
||||
*/
|
||||
private String instanceSuffix = "";
|
||||
|
||||
public String buildFieldName(String property) {
|
||||
switch (propertiesNameStyle) {
|
||||
case UPPER_CASE:
|
||||
return StringUtil.camelToUnderline(property).toUpperCase();
|
||||
case LOWER_CASE:
|
||||
return StringUtil.camelToUnderline(property).toLowerCase();
|
||||
case UPPER_CAMEL_CASE:
|
||||
return StringUtil.firstCharToUpperCase(property);
|
||||
case LOWER_CAMEL_CASE:
|
||||
default:
|
||||
return StringUtil.firstCharToLowerCase(property);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类前缀。
|
||||
*/
|
||||
@ -84,4 +110,31 @@ public class TableDefConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
public NameStyle getPropertiesNameStyle() {
|
||||
return propertiesNameStyle;
|
||||
}
|
||||
|
||||
public TableDefConfig setPropertiesNameStyle(NameStyle propertiesNameStyle) {
|
||||
this.propertiesNameStyle = propertiesNameStyle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getInstanceSuffix() {
|
||||
return instanceSuffix;
|
||||
}
|
||||
|
||||
public TableDefConfig setInstanceSuffix(String instanceSuffix) {
|
||||
this.instanceSuffix = instanceSuffix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public enum NameStyle {
|
||||
|
||||
UPPER_CASE,
|
||||
LOWER_CASE,
|
||||
UPPER_CAMEL_CASE,
|
||||
LOWER_CAMEL_CASE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -311,6 +311,14 @@ public class Column {
|
||||
return importClasses;
|
||||
}
|
||||
|
||||
public boolean isLarge() {
|
||||
if (columnConfig != null && columnConfig.getLarge() != null) {
|
||||
return columnConfig.getLarge();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Column{" +
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#set(tableDefClassName = table.buildTableDefClassName())
|
||||
package #(packageConfig.tableDefPackage);
|
||||
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
@ -9,18 +10,19 @@ import com.mybatisflex.core.table.TableDef;
|
||||
* @author #(javadocConfig.getAuthor())
|
||||
* @since #(javadocConfig.getSince())
|
||||
*/
|
||||
public class #(table.buildTableDefClassName()) extends TableDef {
|
||||
public class #(tableDefClassName) extends TableDef {
|
||||
|
||||
public static final #(table.buildTableDefClassName()) #(table.name) = new #(table.buildTableDefClassName())("#(table.name)");
|
||||
public static final #(tableDefClassName) #(tableDefConfig.buildFieldName(table.buildEntityClassName() + tableDefConfig.instanceSuffix)) = new #(tableDefClassName)("#(table.name)");
|
||||
|
||||
#for(column: table.columns)
|
||||
public QueryColumn #(column.name) = new QueryColumn(this, "#(column.name)");
|
||||
public QueryColumn #(tableDefConfig.buildFieldName(column.property)) = new QueryColumn(this, "#(column.name)");
|
||||
#end
|
||||
|
||||
public QueryColumn[] default_columns = new QueryColumn[]{#for(column: table.columns) #if(!column.name.equals("del_flag"))#(column.name)#if(for.index + 1 != for.size),#end#end#end};
|
||||
public QueryColumn[] all_columns = new QueryColumn[]{#for(column: table.columns) #(column.name)#if(for.index + 1 != for.size),#end#end};
|
||||
public QueryColumn #(tableDefConfig.buildFieldName("allColumns")) = new QueryColumn(this, "*");
|
||||
public QueryColumn[] #(tableDefConfig.buildFieldName("defaultColumns")) = new QueryColumn[]{#for(column: table.columns) #if(!column.isLarge())#(tableDefConfig.buildFieldName(column.property))#if(for.index + 1 != for.size),#end#end#end};
|
||||
|
||||
public #(table.buildTableDefClassName())(String tableName) {
|
||||
public #(tableDefClassName)(String tableName) {
|
||||
super(tableName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user