浅“识”MybatisPlus(源码)

  1. 构建sqlSessionFactory
    com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration#sqlSessionFactory
    

  2. 获取SqlSessionFactory对象。

    1、获取SqlSessionFactory对象。
    2、执行 this.afterPropertiesSet(); 
    3、this.sqlSessionFactory = this.buildSqlSessionFactory();
    4、com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean#buildSqlSessionFactory。
    5、xmlMapperBuilder.parse(); 这里是循环解析mapper.xml
    6、this.bindMapperForNamespace();
    7、this.configuration.addMapper(boundType);
    
    
    
    
    

3、com.baomidou.mybatisplus.core.injector.AbstractSqlInjector#inspectInject

 处理(封装tableInfo):

            一、TableInfoHelper.initTableInfo 解析class上的注解。

            二、tableInfo.setKeySequence((KeySequence)clazz.getAnnotation(KeySequence.class));

            三、 OrderBy、TableId、TableLogic、TableField。

4、  上图的methodList.forEach(m.inject)。函数初始化sql脚本

methodList 来源:::
Stream.Builder<AbstractMethod> builder = Stream.builder().add(new Insert()).add(new Delete()).add(new DeleteByMap()).add(new Update()).add(new SelectByMap()).add(new SelectCount()).add(new SelectMaps()).add(new SelectMapsPage()).add(new SelectObjs()).add(new SelectList()).add(new SelectPage());

每一个sqlmethond对应了sql脚本。

String columnScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlColumnMaybeIf((String)null), ""("", "")"", (String)null, "","");
String valuesScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlPropertyMaybeIf((String)null)"

最终解析为sqlSource 对象,构建好的MappedStatement存放 org.apache.ibatis.session.Configuration#mappedStatements

 5、对象解析sql

一、com.baomidou.mybatisplus.core.override.MybatisMapperProxy#invoke

核心入口:org.apache.ibatis.session.Configuration#newStatementHandler

org.apache.ibatis.scripting.xmltags.DynamicSqlSource#getBoundSql 

this.rootSqlNode.apply(context);  注意:rootSqlNode 指向一般是MixedSqlNode

 

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值