Springboot整合mybatis,配置驼峰命名转换(例:userId --user_id)

如题:两种配置方式

1.

springboot的配置文件 添加:

mybatis.configuration.mapUnderscoreToCamelCase=true 或

mybatis.configuration.map-underscore-to-camel-case=true(根据版本不同)

2.通过@configuration配置的方式

@Bean(name = "sqlSessionFactory")
    public SqlSessionFactory sqlSessionFactoryBean() throws IOException {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        bean.setMapperLocations(resolver.getResources("classpath:/mapper/**/**.xml"));
        try {
            //开启驼峰命名转换
            bean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
            return bean.getObject();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

 

你可能感兴趣的:(Springboot)