Mybatis拦截器机制以及Mybatis物理分页操作指南
2016-05-11 10:07
232 查看
以下按照代码执行顺序从.xml配置文件开始,浅析Mybatis拦截器机制在整个运行过程中的主要环节。
XMLConfigBuilder.pluginElement(XNode parent)
从xml配置文件中生成的Configuration对象中包含了plugin在内的所有属性,
1. xml配置文件
1.解析xml中的plugin节点,将interceptor添加到Configuration中XMLConfigBuilder.pluginElement(XNode parent)
从xml配置文件中生成的Configuration对象中包含了plugin在内的所有属性,
package org.apache.ibatis.binding; import java.io.Serializable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Map; import org.apache.ibatis.reflection.ExceptionUtil; import org.apache.ibatis.session.SqlSession; /** * @author Clinton Begin * @author Eduardo Macarron */ public class MapperProxy<T> implements InvocationHandler, Serializable { private static final long serialVersionUID = -6424540398559729838L; private final SqlSession sqlSession; private final Class<T> mapperInterface; private final Map<Method, MapperMethod> methodCache; public MapperProxy(SqlSession sqlSession, Class<T> mapperInterface, Map<Method, MapperMethod> methodCache) { this.sqlSession = sqlSession; this.mapperInterface = mapperInterface; this.methodCache = methodCache; } @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass())) { try { return method.invoke(this, args); } catch (Throwable t) { throw ExceptionUtil.unwrapThrowable(t); } } final MapperMethod mapperMethod = cachedMapperMethod(method); return mapperMethod.execute(sqlSession, args); } private MapperMethod cachedMapperMethod(Method method) { MapperMethod mapperMethod = methodCache.get(method); if (mapperMethod == null) { mapperMethod = new MapperMethod(mapperInterface, method, sqlSession.getConfiguration()); methodCache.put(method, mapperMethod); } return mapperMethod; } }
相关文章推荐
- setValue:forUndefinedKey
- socket编程浅谈
- 自定义复选框、单选按钮外观方法。支持IE、Firefox、chrome
- OpenGL、OpenGL ES、OpenVG、GLX、EGL简介
- 交叉编译busybox
- Kafka的NIO通信机制
- JAVA字符串操作
- JAVA文本框和文本域
- bootstrap 简单教程
- 开始使用C++11的9个理由
- libwebsockets 编译运行测试
- Linux常用命令(六)网络操作命令
- document.all用法
- 注册登录
- mysql查询一天,查询一周,查询一个月的数据【转】
- 开发中碰到的问题:java.lang.IllegalArgumentException: quality must be 0..100
- python数据结构之字符串查找两例
- salt
- Http认证之Basic认证
- CXF Spring 使用