mybatis拦截器的注解说明
来源:互联网 发布:landsat的波段数据 编辑:程序博客网 时间:2024/06/09 22:08
@Intercepts( { @Signature(type = Executor.class,method = "query",
args = {MappedStatement.class, Object.class, RowBounds.class,ResultHandler.class
) })
type:表示拦截的类,这里是Executor的实现类
method:表示拦截的方法,这里是拦截Executor的query方法
args:表示方法参数
List query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException;
封装Interceptor对象(org.apache.ibatis.plugin.Plugin)
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);
}
}
如下是@Signature的解析代码(org.apache.ibatis.plugin.Plugin)
private static Map<Class<?>, Set<Method>> getSignatureMap(Interceptor interceptor) {
Signature[] sigs = interceptor.getClass().getAnnotation(Intercepts.class).value();//获取@Signature对象数组
//[ @org.apache.ibatis.plugin.Signature(type=interface org.apache.ibatis.executor.Executor, method=query, args=[class org.apache.ibatis.mapping.MappedStatement, class Java.lang.Object, class org.apache.ibatis.session.RowBounds, interface org.apache.ibatis.session.ResultHandler]) ]
Map<Class<?>, Set<Method>> signatureMap = new HashMap<Class<?>, Set<Method>>();
for (Signature sig : sigs) {
Set<Method> methods = signatureMap.get(sig.type());
if (methods == null) {
methods = new HashSet<Method>();
signatureMap.put(sig.type(), methods);
}
try {
Method method = sig.type().getMethod(sig.method(), sig.args());
methods.add(method);
} catch (NoSuchMethodException e) {
throw new PluginException("Could not find method on " + sig.type() + " named " + sig.method() + ". Cause: " + e, e);
}
}
return signatureMap;
}
Plugin类负责生成代理,调用具体的拦截器实现类
- mybatis拦截器的注解说明
- mybatis拦截器的注解说明
- mybatis 分页插件拦截注解不同版本不同的写法
- mybatis 拦截器的理解
- struts2注解下的拦截器配置
- struts2基于注解的拦截器配置
- struts2注解下的拦截器配置
- java的 自定义注解拦截器
- webwork的拦截器的说明
- mybatis拦截器的执行顺序
- mybatis实现拦截器的方法
- MyBatis Excutor 拦截器的巧妙用法
- springmvc+mybatis中拦截器的使用
- mybatis拦截器的执行顺序
- 9、Mybatis拦截器的源码分析
- 10、自定义mybatis的plugin拦截器
- mybatis分页拦截器的实现
- struts2拦截器--注解
- 板子上实现ftpd
- Sublime Text 2 (for OS X )配置成可以运行基于python3解释器的 .py文件
- 频道管理的简单使用
- 判断是否为素数的另一种解法
- 数据结构
- mybatis拦截器的注解说明
- SQL Server数据类型与C#类型对应关系
- Python学习笔记(二)——编程0基础数据分析进阶之路
- 分享两种最简单的Android打渠道包的方法
- 自动行为操控(Steering)(一)—框架
- Maven 检出项目或删除repository后 pom报错解决方案
- SDWebImage 加载显示 GIF 与性能问题
- 查询包含某个字段的表
- ubuntu 14.04源码编译bitcoin