Mybatis源码解析之核心类分析
Mybatis源码解析之初始化分析
Mybatis源码解析之执行流程解析
Mybatis源码解析之数据库连接和连接池
Mybatis源码解析之事务管理
Mybatis源码解析之缓存机制(一):一级缓存
Mybatis源码解析之缓存机制(二):二级缓存
为了保证程序的扩展性,提供使用者在框架基础上增强自定义的逻辑处理,mybatis提供了一种基于拦截器的插件机制。
一、Interceptor接口
public interface Interceptor {
//覆盖原来的方法逻辑
Object intercept(Invocation invocation) throws Throwable;
//为被拦截的对象生成一个代理对象
Object plugin(Object target);
//设置配置的属性值
void setProperties(Properties properties);
}
在Mybatis中想实现插件就必须实现Interceptor接口。
二、InterceptorChain类
public class InterceptorChain {
private final List<Interceptor> interceptors = new ArrayList<Interceptor>();
public Object pluginAll(Object target) {
for (Interceptor interceptor : interceptors) {
target = interceptor.plugin(target);
}
return target;
}
public