上一篇 <<<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常见面试题
网友评论