首先在mybatis中要使用插件你必须实现:
- org.apache.ibatis.plugin.Interceptor接口
- 有三个方法:
- intercept 真个是插件真正运行的方法,
- 它将直接覆盖掉你真实拦截对象的方法。
- 里面有一个Invocation对象,利用它可以调用你原本要拦截的对象的方法
- plugin 它是一个生成动态代理对象的方法,
- setProperties 它是允许你在使用插件的时候设置参数值。
- intercept 真个是插件真正运行的方法,
初始化:
- XMLConfigBuilder
- private void parseConfiguration(XNode root)
- pluginElement(root.evalNode("plugins"));
- private void parseConfiguration(XNode root)
Executor对象的取出:
- Configuration 类下面
- public Executor newExecutor(Transaction transaction, ExecutorType executorType)
- executor = (Executor) interceptorChain.pluginAll(executor);
-
public Object plugin(Object target) { return Plugin.wrap(target, this); }
- Map<Class<?>, Set<Method>> signatureMap = getSignatureMap(interceptor);
-
- executor = (Executor) interceptorChain.pluginAll(executor);
- public Executor newExecutor(Transaction transaction, ExecutorType executorType)