-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Please add an option to control the naming style of the generated fields in DynamicSqlSupport classes.
The current lowerCamelCase style often shadows method parameter names, forcing developers to introduce artificial prefixes or abbreviations, which hurts readability.
Current lowerCamelCase (problematic):
public final class CodeDynamicSqlSupport {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final CodeTable codeTable = new CodeTable();
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> id = codeTable.id;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> code = codeTable.code;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<String> message = codeTable.message;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final class CodeTable extends AliasableSqlTable<CodeTable> {
public final SqlColumn<Integer> id = column("`id`", JDBCType.INTEGER);
public final SqlColumn<Integer> code = column("`code`", JDBCType.INTEGER);
public final SqlColumn<String> message = column("`message`", JDBCType.VARCHAR);
public CodeTable() {
super("sys_code", CodeTable::new);
}
}
}
import static com.mapper.support.CodeDynamicSqlSupport.*;
public Code findByCode(int _code) { // had to rename parameter
SelectStatementProvider provider = select()
.from(codeTable)
.where(code, isEqualTo(_code)).build()
.render(RenderingStrategies.MYBATIS3);
}Desired UPPER_SNAKE_CASE (no shadowing, clean API):
public final class CodeDynamicSqlSupport {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final CodeTable CODE_TABLE = new CodeTable();
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> ID = CODE_TABLE.ID;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> CODE = CODE_TABLE.CODE;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<String> MESSAGE = CODE_TABLE.MESSAGE;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final class CodeTable extends AliasableSqlTable<CodeTable> {
public final SqlColumn<Integer> ID = column("`id`", JDBCType.INTEGER);
public final SqlColumn<Integer> CODE = column("`code`", JDBCType.INTEGER);
public final SqlColumn<String> MESSAGE = column("`message`", JDBCType.VARCHAR);
public CodeTable() {
super("sys_code", CodeTable::new);
}
}
}
// usage
import static com.mapper.support.CodeDynamicSqlSupport.*;
public Code findByCode(int code) {
SelectStatementProvider provider = select()
.from(CODE_TABLE)
.where(CODE, isEqualTo(code)).build()
.render(RenderingStrategies.MYBATIS3);
}A simple generator property like
<property name="dynamicSqlSupportNamingStyle" value="UPPER_SNAKE_CASE"/>
(defaulting to the current style for backward compatibility) would eliminate these naming conflicts and make the generated code far more pleasant to use.
Metadata
Metadata
Assignees
Labels
No labels