baomidou/mybatis-plus · error · RuntimeException

的名称转换结果为空,请检查是否配置问题

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.

Solutions

  1. Inspect the table name shown in the message and compare it against your StrategyConfig tablePrefix/tableSuffix values; the affix removal consumed the whole name.
  2. Narrow the prefix/suffix (e.g. use 'sys_' instead of 'sys') or rename the offending table so a non-empty stem remains.
  3. Exclude the offending table via strategyConfig.include()/addInclude so it is not generated, if its name cannot change.
  4. 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

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


AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14). Data as JSON: /api/errors/28b649c9e689eb73. Report an issue: GitHub.

Appendix: 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)