总体流程:
测试用例:
(1)调用DefaultSqlSession的getMapper():在里面调用configuration的getMapper();
参数type:传进来的EmployeeMapper.class
(2)调用configuration的getMapper():
mapperRegistry对象里面拥有一个hashMap,存储接口com.starfall.mybaits.dao.EmployeeMapper和接口工厂org.apache.ibatis.binding.MapperProxyFactory@7fee8714
(3)调用mapperRegistry的getMapper():
先从mapperRegistry的knownMappers属性中get到MapperProxyFactory,
再通过MapperProxyFactory调用newInstance()方法。
(4)调用mapperProxyFactory的newInstance(sqlSession)方法:
使用sqlSession, mapperInterface, methodCache对象new一个MapperProxy对象,MapperProxy实现InvocationHandler接口,即MapperProxy是一个mapper接口的动态代理类。
继续调用newInstance(mapperProxy):
通过Proxy代理类动态创建一个代理对象的类:
(5)最终返回代理对象