Skip to content

Commit 86f34c9

Browse files
author
jesper
committed
update spring
1 parent 5d1c6b9 commit 86f34c9

File tree

8 files changed

+533
-192
lines changed

8 files changed

+533
-192
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
- [系统设计](https://github.com/zaiyunduan123/Java-Interview/blob/master/notes/scene/Scene-Design.md)
4949

5050
### 框架原理
51-
- [SSM实现原理](https://github.com/zaiyunduan123/Java-Interview/blob/master/notes/framework/Framework.md)
51+
- [Spring实现原理](https://github.com/zaiyunduan123/Java-Interview/blob/master/notes/framework/Spring.md)
52+
53+
- [MyBatis实现原理](https://github.com/zaiyunduan123/Java-Interview/blob/master/notes/framework/MyBatis.md)
5254

5355
- [Solr实现原理](https://github.com/zaiyunduan123/Java-Interview/blob/master/notes/framework/Solr.md)
5456

image/spring-1.png

32 KB
Loading

image/spring-2.png

28.1 KB
Loading

image/spring-3.png

25.5 KB
Loading

notes/framework/Framework.md

Lines changed: 0 additions & 191 deletions
This file was deleted.

notes/framework/MyBatis.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3+
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4+
5+
- [MyBatis原理](#mybatis%E5%8E%9F%E7%90%86)
6+
- [MyBatis缓存](#mybatis%E7%BC%93%E5%AD%98)
7+
8+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
9+
10+
# MyBatis原理
11+
**MyBatis完成2件事情**
12+
13+
1. 封装JDBC操作
14+
2. 利用反射打通Java类与SQL语句之间的相互转换
15+
16+
**MyBatis的主要成员**
17+
18+
1. Configuration MyBatis所有的配置信息都保存在Configuration对象之中,配置文件中的大部分配置都会存储到该类中
19+
2. SqlSession 作为MyBatis工作的主要顶层API,表示和数据库交互时的会话,完成必要数据库增删改查功能
20+
3. Executor MyBatis执行器,是MyBatis 调度的核心,负责SQL语句的生成和查询缓存的维护
21+
4. StatementHandler 封装了JDBC Statement操作,负责对JDBC statement 的操作,如设置参数等
22+
5. ParameterHandler 负责对用户传递的参数转换成JDBC Statement 所对应的数据类型
23+
6. ResultSetHandler 负责将JDBC返回的ResultSet结果集对象转换成List类型的集合
24+
7. TypeHandler 负责java数据类型和jdbc数据类型(也可以说是数据表列类型)之间的映射和转换
25+
8. MappedStatement MappedStatement维护一条select|update|delete|insert节点的封装
26+
9. SqlSource 负责根据用户传递的parameterObject,动态地生成SQL语句,将信息封装到BoundSql对象中,并返回
27+
10. BoundSql 表示动态生成的SQL语句以及相应的参数信息
28+
29+
30+
![](https://github.com/zaiyunduan123/Java-Interview/blob/master/image/frame-2.jpg)
31+
32+
33+
# MyBatis缓存
34+
35+
MyBatis提供查询缓存,用于减轻数据库压力,提高性能。MyBatis提供了一级缓存和二级缓存。
36+
![](https://github.com/zaiyunduan123/Java-Interview/blob/master/image/frame-3.jpg)
37+
38+
1. 一级缓存是SqlSession级别的缓存,每个SqlSession对象都有一个哈希表用于缓存数据,不同SqlSession对象之间缓存不共享。同一个SqlSession对象对象执行2遍相同的SQL查询,在第一次查询执行完毕后将结果缓存起来,这样第二遍查询就不用向数据库查询了,直接返回缓存结果即可。一级缓存是MyBatis内部实现的一个特性,用户不能配置,默认情况下自动支持的缓存,用户没有定制它的权利
39+
40+
2. 二级缓存是Application应用级别的缓存,它的是生命周期很长,跟Application的声明周期一样,也就是说它的作用范围是整个Application应用。MyBatis默认是不开启二级缓存的,可以在配置文件中使用如下配置来开启二级缓存
41+
```xml
42+
<settings>
43+
<setting name="cacheEnabled" value="true"/>
44+
</settings>
45+
```

0 commit comments

Comments
 (0)