mybatis-flex / mybatis-flex

mybatis-flex is an elegant Mybatis Enhancement Framework

Home Page:https://mybatis-flex.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

全局配置FlexConfiguration::setMapUnderscoreToCamelCase无效!!!

iQiFengLe opened this issue · comments

    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
        SqlSessionFactoryBean factory = new FlexSqlSessionFactoryBean();
        factory.setDataSource(dataSource);
        factory.setVfs(SpringBootVFS.class);
        FlexConfiguration configuration = new FlexConfiguration();
        configuration.setMapUnderscoreToCamelCase(false);
        factory.setConfiguration(configuration);
        return factory.getObject();
    }

原因为创建表信息对象时,只获取了注解的信息,并没有从配置中加载!!

TableInfoFactory::createTableInfo

 private static TableInfo createTableInfo(Class<?> entityClass) {

        TableInfo tableInfo = new TableInfo();
        tableInfo.setEntityClass(entityClass);
        Reflector reflector = Reflectors.of(entityClass);
        tableInfo.setReflector(reflector);

        // 初始化表名
        Table table = entityClass.getAnnotation(Table.class);
        if (table == null) {
            TableRef vo = entityClass.getAnnotation(TableRef.class);
            if (vo != null) {
                TableInfo refTableInfo = ofEntityClass(vo.value());
                // 设置 VO 类对应的真实的表名
                tableInfo.setSchema(refTableInfo.getSchema());
                tableInfo.setTableName(refTableInfo.getTableName());
                // 将 @Table 注解的属性复制到 VO 类当中
                if (vo.copyTableProps()) {
                    tableInfo.setComment(refTableInfo.getComment());
                    tableInfo.setCamelToUnderline(refTableInfo.isCamelToUnderline());
                    tableInfo.setDataSource(refTableInfo.getDataSource());

                    tableInfo.setOnSetListeners(refTableInfo.getOnSetListeners());
                    tableInfo.setOnInsertColumns(refTableInfo.getOnInsertColumns());
                    tableInfo.setOnUpdateListeners(refTableInfo.getOnUpdateListeners());
                }
            } else {
                // 默认为类名转驼峰下划线
                String tableName = StringUtil.camelToUnderline(entityClass.getSimpleName());
                tableInfo.setTableName(tableName);
            }
        } else {
            tableInfo.setSchema(table.schema());
            tableInfo.setTableName(table.value());
            tableInfo.setCamelToUnderline(table.camelToUnderline());
            tableInfo.setComment(table.comment());

            if (table.onInsert().length > 0) {
                List<InsertListener> insertListeners = Arrays.stream(table.onInsert())
                    .filter(listener -> listener != NoneListener.class)
                    .map(ClassUtil::newInstance)
                    .collect(Collectors.toList());
                tableInfo.setOnInsertListeners(insertListeners);
            }