- 构建sqlSessionFactory
com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration#sqlSessionFactory
-
获取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