sqlSession如何获得具体的Mapper接口信息

作者: 迦叶_金色的人生_荣耀而又辉煌 | 来源:发表于2021-02-06 06:18 被阅读0次

上一篇 <<<SqlSession的创建过程
下一篇 >>>userMapper.getUser(1);底层实现原理


实现原理

a、从Configuration的MapperRegistry中获得代理工厂MapperProxyFactory信息
b、根据代理工厂信息实例化JDK具体的代理类

核心代码

Configuration.mapperRegistry.getMapper(type, sqlSession);
type:interface com.jarye.mapper.UserMapper

-->MapperProxyFactory<T> mapperProxyFactory = (MapperProxyFactory)MapperRegistry.knownMappers.get(type);
    return mapperProxyFactory.newInstance(sqlSession);

        ---->MapperProxy<T> mapperProxy = new MapperProxy(sqlSession, MapperProxyFactory.mapperInterface, MapperProxyFactory.methodCache);
        return Proxy.newProxyInstance(MapperProxyFactory.mapperInterface.getClassLoader(), new Class[]{MapperProxyFactory.mapperInterface}, mapperProxy);
        mapperInterface:interface com.jarye.mapper.UserMapper

图解说明


推荐阅读:
<<<Mybatis的整体执行原理图解
<<<SqlSessionFactory的创建过程原理
<<<SqlSession的创建过程
<<<userMapper.getUser(1);底层实现原理
<<<sqlSession.selectOne底层实现原理
<<<Mybatis一级缓存知识汇总
<<<Mybatis二级缓存知识汇总
<<<Springboot整合Mybatis二级缓存
<<<Mybatis常见面试题

相关文章

网友评论

    本文标题:sqlSession如何获得具体的Mapper接口信息

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