美文网首页
6. interceptorChain

6. interceptorChain

作者: 元隐 | 来源:发表于2020-01-15 19:20 被阅读0次

mybatis 的interceptorChain是给扩展用的, 常用的比如分页扩展插件. mybatis提供的rowbounds实质上是采用 fetchSize, rs.next 这种方式. 其性能很差. (实际上就是游标, .next() 一点点向下滚动)

其采用了反射,一个典型的Interceptor

@Intercepts({
        @Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class,
                RowBounds.class, ResultHandler.class }),
        @Signature(type = Executor.class, method = "close", args = { boolean.class }) })
public class MyBatisInterceptor implements Interceptor {

    private Integer value;

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        //do something
        
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        //do something
    }

}

比如分页插件可以通过增强以下接口实现

public interface StatementHandler {
    <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException;

    BoundSql getBoundSql();
}

详情请参见分页插件源码

相关文章

  • 6. interceptorChain

    mybatis 的interceptorChain是给扩展用的, 常用的比如分页扩展插件. mybatis提供的r...

  • InterceptorChain模式

    最近在看OkHttp源码时,看到了Interceptor的使用,觉得还是很巧妙的设计,所以就提炼出来,已被不时之需...

  • sourceCode

    拦截器 org.apache.ibatis.plugin.InterceptorChain 参数解析的地方 co...

  • OkHttp3源码学习之InterceptorChain

    介绍 拦截器链,采用责任链模式,将一次事物的耦合度降低。 源码分析 RealInterceptorChain Re...

  • 6.

    我和比我年纪小的女孩儿们一起跳舞,这个舞蹈班里,我年龄最大。 一把老骨头了才开始学跳舞,一些考验柔韧度的动作我...

  • 6.

    江边柳 唐 雍裕之 袅袅古堤边,青青一树烟。...

  • 6.

    宁柒回到盛世刚出电梯遇到了匆忙往外走的乔飞。 大飞哥,你这是要去哪啊? 啊 宁柒啊 薇姐和其他部门的人在楼上开会商...

  • 6.

    9-1 等待登机ing....美国,我来了,带着无尽的好感与钦佩,扑面而来...有人说,美国真的是个神奇的国家,能...

  • 6.

    今日打卡金句:【Day4】 What's this? It's an air-conditioner. Is th...

  • 6.

    护照上莫名其妙多了很多中东国家的签证,在土耳其遇到一个强奸犯但是逃走了,后来又遇到一个会说日语的藏族老婆婆其实是上...

网友评论

      本文标题:6. interceptorChain

      本文链接:https://www.haomeiwen.com/subject/mfftzctx.html