Mybatis继承sqlsession 实现自动close

来源:互联网 发布:守望先锋攻击力数据 编辑:程序博客网 时间:2024/06/11 04:13

具体实现可以参考mybatis-spring.jar中的SqlSessionTemplate

SqlSessionTemplate 继承sqlSession接口

并通过动态代理,在SqlSessionInterceptor类代理方法中实现session的自动close

注意 继承的SqlSession的getMapper方法不能使用

public Object getMapper(Class type)
    {
        return sqlSessionFactory.getMapper(type);
    }

而要用:

public Object getMapper(Class type)
    {
        return getConfiguration().getMapper(type, this);
    }




另外:

java动态代理链接

http://blog.csdn.net/kkluxklan/article/details/7961422