根据 id 获取 Mapper.xml 文件的SQL语句
断点位置
org.apache.ibatis.session.Configuration#getMappedStatement(java.lang.String, boolean)
以 select语句为例子

key 为 id,value为 MappedStatement 语句的 map 来存储

用 mappedStatements.get(id) 的方式获取到 MappedStatement 类

加载 Mapper.xml 到 mappedStatements 中的执行流程
启动的 run 方法中加载 SQL,然后解析每一个 mapper.xml 文件

解析出文件中的7条SQL语句

最后给 mappedStatements 添加键值对

这篇博客探讨了如何通过id在MyBatis的Configuration中获取MappedStatement对象,详细阐述了从启动运行到解析mapper.xml文件,最终将SQL语句存储到mappedStatements映射中的过程。以select语句为例,展示了如何利用mappedStatements.get(id)来获取对应的MappedStatement类,揭示了MyBatis内部加载SQL的机制。


被折叠的 条评论
为什么被折叠?



