mybatis周边记录

使用mybatis,对于用到的组件需要明确其作用,这样才能灵活用好组件,熟悉原理,能够更好的评估组件的作用和排查问题。

mybatis 周边

按照依赖的顺序,列出如下,其中pagehelper 和mapper 没有依赖关系

  • mybatis mybatis核心库
  • mybatis-spring mybatis集成spring库
  • mybatis-spring-boot-autoconfigure mybatis spring-boot自动化配置库
  • mybatis-spring-boot-starter 启用spring-boot自动化配置库
  • mapper tk通用Mapper库
  • mapper-spring-boot-autoconfigure tk通用Mapper spring-boot自动化配置库
  • mapper-spring-boot-starter 启用spring-boot自动化配置库
  • pagehelper tk通用分页拦截器
  • pagehelper-spring-boot-autoconfigure tk通用分页拦截器 spring-boot自动化配置库
  • pagehelper-spring-boot-starter 启用spring-boot自动化配置库

mybatis组件核心类

对应上述的组件库,关键类如下:

  • org.apache.ibatis.session.SqlSessionFactory
  • org.mybatis.spring.SqlSessionFactoryBean, org.mybatis.spring.mapper.MapperFactoryBean
  • org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration,
  • tk.mybatis.mapper.mapperhelper.MapperHelper
  • com.github.pagehelper.autoconfigure.MapperAutoConfiguration
  • com.github.pagehelper.PageInterceptor
  • com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration

组件依赖关系spring-boot体现

spring-boot自动配置关键类如下,这三者之间有明确的加载解析顺序,保障容器的正常启动和增强特性的添加。

// mybatis-spring组件依赖mybatis组件,spring-boot自动配置依赖spring-mybatis
@ConditionalOnClass({ SqlSessionFactory.class, SqlSessionFactoryBean.class })
@ConditionalOnBean(DataSource.class)
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class MybatisAutoConfiguration {}

// mapper 依赖spring-mybatis,该组件基于Mapper bean的能力增强
@ConditionalOnBean(SqlSessionFactory.class)
@AutoConfigureAfter(MybatisAutoConfiguration.class)
public class MapperAutoConfiguration {}

// pagehelper 依赖spring-mybatis,该组件基于Mapper bean的能力增强
@ConditionalOnBean(SqlSessionFactory.class)
@AutoConfigureAfter(MybatisAutoConfiguration.class)
public class PageHelperAutoConfiguration implements EnvironmentAware {}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值