mybatis拦截器

【可以拦截的类】

Executor、ParameterHandler、ResultSetHandler、StatementHandler

【注意事项】

通过代理实现,假如执行方法时实例已经不是代理,将不能拦截。比如要拦截的类自己调用的方法。

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
      Set<Method> methods = signatureMap.get(method.getDeclaringClass());
      if (methods != null && methods.contains(method)) {
        return interceptor.intercept(new Invocation(target, method, args));
      }
      return method.invoke(target, args);
    } catch (Exception e) {
      throw ExceptionUtil.unwrapThrowable(e);
    }
  }

Plugin(implements InvocationHandler)部分源码。

 

http://haohaoxuexi.iteye.com/blog/1851081

posted @ 2014-10-06 18:38  爱上飞飞的面码  阅读(1301)  评论(0编辑  收藏  举报