
mybatis mapper原理.jpg
MapperProxy.invoke)。MapperProxy.invoke中的MapperMethod.execute)。但最终都交给SqlSession执行。mapperMethod.execute(sqlSession, args);调用了MapperProxy缓存的MapperMethod,后者对各种数据库操作都进行人性化的处理,但都是交给SqlSession执行的。
可以看到,所有类都关联着SqlSession
newInstance方法创建一个Mapper代理对象。MapperProxyFactory.newInstance(SqlSession sqlSession)方法创建了中间类对象MapperProxy(implements InvocationHandler),进而用MapperProxyFactory.newInstance(MapperProxy<T> mapperProxy)方法创建了对应Mapper的代理类对象。