一、配置文件解析
配置文件的结构
mybatis-config.xml
<configuration>
<properties resource="config/database.properties"/>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mybatis/customerMapper.xml"/>
</mappers>
</configuration>
xxxMapper.xml
<mapper namespace="com.huawei.esight.customer.mapper.CustomerMapper">
<select id="selectById" resultType="com.huawei.esight.customer.model.Customer">
SELECT * FROM customer where id = #{id}
</select>
<insert></insert>
<delete></delete>
<update></update>
</mapper>
配置文件的解析流程即将上述的XML文件元素转换成对应的Java对象过程,其最终的转换对象及其关系如下图:
配置元素解析构造器
org.apache.ibatis.builder.xml.XMLConfigBuilder
org.apache.ibatis.builder.xml.XMLMapperBuilder
org.apache.ibatis.builder.xml.XMLStatementBuilder
SqlStatement构建流程
【mybatis-config.xml文件解析】
org.apache.ibatis.builder.xml.XMLConfigBuilder#parse
org.apache.ibatis.builder.xml.XMLConfigBuilder#parseConfiguration
org.apache.ibatis.builder.xml.XMLConfigBuilder#mapperElement
【mapper.xml文件解析】
org.apache.ibatis.builder.xml.XMLMapperBuilder#parse
org.apache.ibatis.builder.xml.XMLMapperBuilder#configurationElement
org.apache.ibatis.builder.xml.XMLMapperBuilder#buildStatementFromContext
【statement sql块解析】
org.apache.ibatis.builder.xml.XMLStatementBuilder#parseStatementNode
org.apache.ibatis.builder.MapperBuilderAssistant#addMappedStatement
二、会话创建 SqlSession
SqlSession对象结构
未完待续。。。