mybatis-plus 和Spring Boot咋集成?

ff100 发布于 2016/09/21 16:36
阅读 1K+
收藏 0

@青苗 你好,想跟你请教个问题:

mybatis-plus 和Spring Boot 能集成么?咋集成?有具体的例子么?

加载中
0
青苗
青苗
xxConfig.java
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public SqlSessionFactory getMybatisSqlSessionFactoryBean(DataSource myDs) throws Exception {
    MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
    factoryBean.setDataSource(myDs);
    ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
    factoryBean.setTypeAliasesPackage("com.xb.persistent");
    Resource[] resources = resolver.getResources("classpath:/com/xxxx/persistent/mapper/*.xml");
    factoryBean.setMapperLocations(resources);
    factoryBean.setCache(null);
    PageHelper pageHelper = new com.github.pagehelper.PageHelper();
    Properties p = new Properties();
    p.setProperty("dialect", "mysql");
    pageHelper.setProperties(p);
    factoryBean.setPlugins(new Interceptor[]{pageHelper});
    return factoryBean.getObject();
}


@Bean
public MapperScannerConfigurer getMapperScannerConfigurer() {
    MapperScannerConfigurer scanConf = new MapperScannerConfigurer();
    scanConf.setBasePackage("com.xxxx.persistent.mapper");
    return scanConf;
}




返回顶部
顶部