baomidou/mybatis-plus · error · RuntimeException
%s 的名称转换结果为空,请检查是否配置问题
Error message
%s 的名称转换结果为空,请检查是否配置问题
What it means
Thrown by INameConvert.processName when, after removing the configured table prefix and/or suffix, the remaining name is blank. The generator refuses to build a class/property name from an empty string, because prefix/suffix stripping consumed the entire table name. The original table name is included in the message so you can see which table triggered it.
Source
Thrown at mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/INameConvert.java:85
}
@Override
public @NotNull String propertyNameConvert(@NotNull TableField field) {
return processName(field.getName(), strategyConfig.entity().getColumnNaming(), strategyConfig.getFieldPrefix(), strategyConfig.getFieldSuffix());
}
private String processName(String name, NamingStrategy strategy, Set<String> prefix, Set<String> suffix) {
String propertyName = name;
// 删除前缀
if (!prefix.isEmpty()) {
propertyName = NamingStrategy.removePrefix(propertyName, prefix);
}
// 删除后缀
if (!suffix.isEmpty()) {
propertyName = NamingStrategy.removeSuffix(propertyName, suffix);
}
if (StringUtils.isBlank(propertyName)) {
throw new RuntimeException(String.format("%s 的名称转换结果为空,请检查是否配置问题", name));
}
// 下划线转驼峰
if (NamingStrategy.underline_to_camel.equals(strategy)) {
return NamingStrategy.underlineToCamel(propertyName);
}
return propertyName;
}
}
}
View on GitHub (pinned to bf67d90747)
Solutions
- Inspect the table name shown in the message and compare it against your StrategyConfig tablePrefix/tableSuffix values; the affix removal consumed the whole name.
- Narrow the prefix/suffix (e.g. use 'sys_' instead of 'sys') or rename the offending table so a non-empty stem remains.
- Exclude the offending table via strategyConfig.include()/addInclude so it is not generated, if its name cannot change.
- Implement a custom INameConvert that returns a safe default when stripping produces an empty string.
Example fix
// before
StrategyConfig strategy = new StrategyConfig();
strategy.setTablePrefix("sys"); // table named 'sys' -> strips to ""
// after
StrategyConfig strategy = new StrategyConfig();
strategy.setTablePrefix("sys_"); // table 'sys_user' -> 'user' Defensive patterns
Strategy: validation
Validate before calling
// Before generating: ensure no table name is fully consumed by affixes
Set<String> prefix = strategyConfig.getTablePrefix();
Set<String> suffix = strategyConfig.getTableSuffix();
for (String table : allTableNames /* from DatabaseMetaData getTables */) {
String rest = table;
for (String p : prefix) if (rest.startsWith(p)) { rest = rest.substring(p.length()); break; }
for (String s : suffix) if (rest.endsWith(s) && rest.length() > s.length()) { rest = rest.substring(0, rest.length() - s.length()); break; }
if (rest.isBlank()) throw new IllegalStateException("Affix config empties table name: " + table);
} Try / catch
try {
generator.generate();
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("名称转换结果为空")) {
// log offending table from message, fix prefix/suffix config
}
throw e;
} Prevention
- Prefer prefix values that include the separator (sys_ not sys) so they can never equal a whole table name.
- Keep the table list (include) explicit when using aggressive affix stripping.
- Unit-test the generator config against the real table list in CI so bad affixes fail at build time.
When it happens
Trigger: Calling the code generator with strategyConfig.tablePrefix or tableSuffix set to a value equal to the whole table name (e.g. table 'sys' with prefix 'sys'), or a prefix/suffix that matches after case differences, so NamingStrategy.removePrefix/removeSuffix leaves an empty string before the underline-to-camel step.
Common situations: Setting tablePrefix too greedily (e.g. prefix 't' against a table named 't'), copying a prefix configuration from another project whose tables share a prefix, or combining a short table name with a long configured suffix. Also happens when entity name conversion (entityNameConvert) is fed a table whose name equals the removed affix.
Related errors
- `include` and `exclude` configurations are mutually exclusiv
- `likeTable` and `notLikeTable` configurations are mutually e
- 读取[%s]字段出错!
- %s already contains value for %s
- %s does not contain value for %s
AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14).
Data as JSON: /api/errors/28b649c9e689eb73.
Report an issue: GitHub.