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

上一篇 << 下一篇 >>>userMapper.getUser(1);底层实现原理


实现原理

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

核心代码

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

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

        ---->MapperProxy 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

图解说明


推荐阅读:
<< << << << << << << << << <<

你可能感兴趣的:(sqlSession如何获得具体的Mapper接口信息)