获取接口的实现类对象
第三步看获取接口的实现类对象,主要就是opnSession对象的getMApper方法,使用MapperProxyFactory返回MapperProxy的代理对象,这个代理对象里面包含了DefaultSqlSessionsql
【一句话总结,就是经过动态代理 用MapperProxy建立接口代理对象】
app
流程图
调用configuration的getMapper()方法
spa
mapperRegistry.getMapper()
调用mapperRegistry.getMapper() 方法
mapperRegistry.getMapper()方法以下:
.net
获取MapperProxyFactory
configuration的mapperRegistry属性保存了 接口对应的工厂
mapperRegistry.getMapper() 方法第一步就先根据接口类型获取MapperProxyFactory
3d
mapperProxyFactory.newInstance(sqlSession)
由于咱们最后是用mapperProxy建立一个mapper,其中用的就是Proxy.newProxyInstance()这个方法建立对象,这个方法须要传入InvocationHandler。
咱们的 MapperProxy 就实现了InvocationHandler,这里new MapperProxy 就是Proxy.newProxyInstance()要用到的第三个参数
具体和AOP底层原理部分建立代理对象均可以一一对应。
代理
首先new 了一个MapperProxy,而后再建立MApperProxy的代理对象
最后得到的代理对象
code
MapperProxy
MapperProxy 实现了InvocationHandler(作动态代理须要proxy对象 须要传入InvocationHandler)
对象