Mybatis-Plus
- 通过重写Configuration、MapperAnnotationBuilder、SqlSessionFactoryBuilder、MybatisSqlSessionFactoryBean等类,修改构建SqlSessionFactory过程。
- 通过@MapperScan注解,对继承BaseMapper接口的接口自动注入增删改查方法
MybatisPlusAutoConfiguration
自动配置注入SqlSessionFactory对象
@Bean
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
...
return factory.getObject();
}
MybatisSqlSessionFactoryBean
构建SqlSessionFactory对象
protected SqlSessionFactory buildSqlSessionFactory() throws Exception {
final Configuration targetConfiguration;
...
final SqlSessionFactory sqlSessionFactory = new MybatisSqlSessionFactoryBuilder().build(targetConfiguration);
...
return sqlSessionFactory;
}
MybatisMapperAnnotationBuilder
重写MapperAnnotationBuilder,增加了注入默认CRUD的SQL
// TODO 注入 CURD 动态 SQL , 放在在最后, because 可能会有人会用注解重写sql
if (GlobalConfigUtils.isSupperMapperChildren(configuration, type)) {
GlobalConfigUtils.getSqlInjector(configuration).inspectInject(assistant, type);
}
AbstractSqlInjector
注入sql的具体实现