Mybatis架构设计及源码分析-MappedStatement
2018-05-26 23:16
525 查看
一个MappedStatement对应mapper配置的xml文件中的一条sql语句节点,比如:
<select id="selectBlog" resultType="Blog"> select * from Blog where id = #{id}</select>这条语句就是用一个MappedStatement对象来描述,在Configuration对象中会维护namespace+id与MappedStatement的映射关系,配置文件初始化过程是会解析并设置到下面变量中。
下面我们简要分析下MappedStatement的主要内容:
上面很多属性都和<select id="selectBlog" resultType="Blog"> select * from Blog where id = #{id}</select>这种语句有类似对应关系,暂时不一一介绍,重要的几个参数是parameterMaps和resultMaps以及sqlSource。其中parameterMaps是封装了sql语句的参数信息,resultMaps封装的是返回值信息。SqlSource封装的是sql语句信息,SqlSource内部只有一个接口根据传入的参数计算好BoundSql信息。BoundSql又是什么呢?
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.mybatis.example.BlogMapper"> <select id="selectBlog" resultType="Blog"> select * from Blog where id = #{id} </select> </mapper>
<select id="selectBlog" resultType="Blog"> select * from Blog where id = #{id}</select>这条语句就是用一个MappedStatement对象来描述,在Configuration对象中会维护namespace+id与MappedStatement的映射关系,配置文件初始化过程是会解析并设置到下面变量中。
protected final Map<String, MappedStatement> mappedStatements = new StrictMap<MappedStatement>("Mapped Statements collection");
下面我们简要分析下MappedStatement的主要内容:
private String resource; private Configuration configuration; private String id; private Integer fetchSize; private Integer timeout; private StatementType statementType; private ResultSetType resultSetType; private SqlSource sqlSource; private Cache cache; private ParameterMap parameterMap; private List<ResultMap> resultMaps; private boolean flushCacheRequired; private boolean useCache; private boolean resultOrdered; private SqlCommandType sqlCommandType; private KeyGenerator keyGenerator; private String[] keyProperties; private String[] keyColumns; private boolean hasNestedResultMaps; private String databaseId; private Log statementLog; private LanguageDriver lang; private String[] resultSets;
上面很多属性都和<select id="selectBlog" resultType="Blog"> select * from Blog where id = #{id}</select>这种语句有类似对应关系,暂时不一一介绍,重要的几个参数是parameterMaps和resultMaps以及sqlSource。其中parameterMaps是封装了sql语句的参数信息,resultMaps封装的是返回值信息。SqlSource封装的是sql语句信息,SqlSource内部只有一个接口根据传入的参数计算好BoundSql信息。BoundSql又是什么呢?
相关文章推荐
- Mybatis架构设计及源码分析-一条语句执行的过程
- Mybatis架构设计及源码分析-Mybatis配置文件初始化全过程
- Mybatis架构设计及源码分析-SqlSessionFactory
- Mybatis架构设计及源码分析-SqlSession
- Mybatis架构设计及源码分析-mapper.xml文件解析
- MyBatis架构设计及源代码分析系列(一):MyBatis架构
- 《深入理解mybatis原理(七)》 MyBatis的架构设计以及实例分析
- 教你们MyBatis的架构设计以及实例分析!
- 《深入理解mybatis原理》 MyBatis的架构设计以及实例分析
- MyBatis架构设计及源代码分析系列 :MyBatis架构
- Play Framework2.1源码分析 - 架构设计及线程策略分析
- 【传智播客郑州校区分享】MyBatis的架构设计分析
- 《深入理解mybatis原理》 MyBatis的架构设计以及实例分析
- 《深入理解mybatis原理》 MyBatis的架构设计以及实例分析
- 《深入理解mybatis原理》 MyBatis的架构设计以及实例分析
- Nginx源码分析—架构设计思想
- 有关SpringMVC的架构设计、源码解析、得失分析
- 求 架构设计 的视屏和 设计模式的视频 性能优化 的视频 系统源码分析 的视频 android
- MyBatis的深入原理分析之1-架构设计以及实例分析
- MyBatis的架构设计分析