Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iQiFengLe opened this issue May 6, 2024 · 0 comments

Comments

@iQiFengLe
Copy link

    @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);
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant