Search in sources :

Example 1 with MybatisMapWrapperFactory

use of com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory in project mybatis-plus-samples by baomidou.

the class MybatisPlusConfig method sqlSessionFactory.

@Bean("mybatisSqlSession")
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig) throws Exception {
    MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
    /* 数据源 */
    sqlSessionFactory.setDataSource(dataSource);
    /* 枚举扫描 */
    sqlSessionFactory.setTypeEnumsPackage("com.baomidou.mybatisplus.samples.mysql.enums");
    /* xml扫描 */
    sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*.xml"));
    /* 扫描 typeHandler */
    // sqlSessionFactory.setTypeHandlersPackage("com.baomidou.mybatisplus.samples.mysql.type");
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    /* 驼峰转下划线 */
    configuration.setMapUnderscoreToCamelCase(true);
    MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
    mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
    mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
    sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
    /* map 下划线转驼峰 */
    configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
    sqlSessionFactory.setConfiguration(configuration);
    /* 自动填充插件 */
    globalConfig.setMetaObjectHandler(new MysqlMetaObjectHandler());
    sqlSessionFactory.setGlobalConfig(globalConfig);
    return sqlSessionFactory.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisMapWrapperFactory(com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory) OptimisticLockerInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)1 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)1 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)1 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)1 Bean (org.springframework.context.annotation.Bean)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1