mybatis解析配置文件及sql
2021-09-17 17:48:24 0 举报
mybatis解析ocnfig文件和mapper.xml文件流程图
作者其他创作
大纲/内容
XMLScriptBuilder#parseDynamicTags
parameterMapElement
解析databaseIdProvider内标签
mapperElement
解析typeHandlers内标签
typeHandlerElement
typeAliasesElement
buildStatementFromContext
将解析好的XNode传给下面方法
environmentsElement
objectWrapperFactoryElement
解析typeAliases内标签
解析cache标签
解析/mapper/sql标签
创建
parse方法
返回一个document放入到
这个方法的入参是右边那样的XNode对象集合
解析cache-ref标签
databaseIdProviderElement
EmployeeMapper.xml
XPathParser
<select resultMap=\"BaseResultMap\" id=\"selectOne\"> select * from employee where id =#{id}</select>
propertiesElement
cacheRefElement
解析/mapper/resultMap标签
mybatis-config.xml
root.evalNode(\"mappers\
resultMapElements
evalNode
XMLStatementBuilder#parseStatementNode
XMLConfigBuilder
XMLMapperBuilder#configurationElement
objectFactoryElement
解析objectWrapperFactory内标签
返回MappedStatement
解析objectFactory内标签
MappedStatement.Builder
解析/mapper/parameterMap标签
pluginElement
解析plugins内标签
sqlElement
解析environments内标签
createDocument
到这里一直都是在解析mybatis-config.xml
解析select|insert|update|delete等sql标签
返回MappedStatement并放入到configuration
XMLScriptBuilder#parseScriptNode
XNode
DocumentBuilderImpl
<select resultMap=\"BaseResultMap\" id=\"selectList\"> <foreach item=\"item\" collection=\"ids\" close=\")\" separator=\
parseConfiguration
<mapper namespace=\"org.apache.ibatis.mapper.IEmployeeMapper\"> <resultMap id=\"BaseResultMap\" type=\"org.apache.ibatis.models.Employee\"> <id jdbcType=\"INTEGER\" column=\"id\" property=\"id\"/> <result jdbcType=\"VARCHAR\" column=\"last_name\" property=\"lastName\"/> <result jdbcType=\"INTEGER\" column=\"gender\" property=\"gender\"/> <result jdbcType=\"VARCHAR\" column=\"email\" property=\"email\"/> <result jdbcType=\"INTEGER\" column=\"department_id\" property=\"departmentId\"/> <result jdbcType=\"VARCHAR\" column=\"department_name\" property=\"departmentName\"/> <result jdbcType=\"TIMESTAMP\" column=\"birth\" property=\"birth\"/> <result jdbcType=\"VARCHAR\" column=\"password\" property=\"password\"/> <result jdbcType=\"VARCHAR\" column=\"salt\" property=\"salt\"/> </resultMap> <select resultMap=\"BaseResultMap\" id=\"selectList\"> <foreach item=\"item\" collection=\"ids\" close=\")\" separator=\
返回一个MixedSqlNode
cacheElement
MapperBuilderAssistant#addMappedStatement
XMLMapperBuilder#parse
MappedStatement
从这里开始解析上面EmployeeMapper.xml
<configuration> <typeAliases></typeAliases> <typeHandlers></typeHandlers> <objectFactory type=\"\"></objectFactory> <reflectorFactory type=\"\"></reflectorFactory> <environments default=\"development\"> <environment id=\"development\"> <transactionManager type=\"JDBC\"/> <dataSource type=\"POOLED\"> <property name=\"driver\" value=\"com.mysql.cj.jdbc.Driver\"/> <property name=\"url\" value=\"jdbc:mysql://localhost:3306/cls?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false&zeroDateTimeBehavior=convertToNull\"/> <property name=\"username\" value=\"root\"/> <property name=\"password\" value=\"admin\"/> </dataSource> </environment> </environments> <databaseIdProvider type=\"\"></databaseIdProvider> <mappers> <mapper resource=\"com/alijiejie/mapper/EmployeeMapper.xml\"/> </mappers></configuration>
解析properties内标签
收藏
收藏
0 条评论
下一页