
下载地址:https://github.com/mybatis/mybatis-3
以我下载的 mybatis-3-mybatis-3.4.6 为例,下载完后解压。打开pom.xml
<parent>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-parent</artifactId>
<version>30</version>
<relativePath />
</parent>
发现mybatis源码依赖 mybatis-parent 所以编译前要先下载mybatis-parent
下载地址:https://github.com/mybatis/parent
下载的 mybatis-parent 版本要和mybatis源文件pom.xml 版本一致。
切换到你下载的mybatis-parent目录:
mvn clean install
切换到你下载的mybatis源码目录:
mvn clean
mvn install -Dmaven.test.skip=true
如果出现如下错误:

打开pom.xml 文件注释掉 maven-pdf-plugin 插件
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pdf-plugin</artifactId>
</plugin>
-->
然后重新编译
Builder模式:例如SqlSessionFactoryBuilder、XMLConfigBuilder、XMLMapperBuilder、XMLStatementBuilder、CacheBuilder;
工厂模式:例如SqlSessionFactory、ObjectFactory、MapperProxyFactory;
单例模式:例如ErrorContext和LogFactory;
代理模式:Mybatis实现的核心,比如MapperProxy、ConnectionLogger,用的jdk的动态代理,还有executor.loader包使用了cglib或者javassist达到延迟加载的效果;
组合模式:例如SqlNode和各个子类ChooseSqlNode等;
模板方法模式:例如BaseExecutor和SimpleExecutor,还有BaseTypeHandler和所有的子类例如IntegerTypeHandler;
适配器模式:例如Log的Mybatis接口和它对jdbc、log4j等各种日志框架的适配实现;装饰者模式:例如Cache包中的cache.decorators子包中等各个装饰者的实现;
迭代器模式:例如迭代器模式PropertyTokenizer;