Mybatis
注意MapperProxy里面有invoke方法,當進到invoker方法會拿到
二、mybatis整合Spring
1、當我們的拿到的【Dao】其實就是【MapperProxy】,執行Dao的方法時,會被MapperProxy的【Invoke方法攔截】
2、圖上已經標注了MapperProxy包含哪些屬性,在Invoke方法里面,就是通過這些屬性,【執行sql】。
1、Mybatis和Spring整合后,獲取Dao的代理對象是通過MapperFactoryBean,而不是之前的MapperProxyFactory,
2、但是MapperFactoryBean其實也是間接從MapperProxyFactory里面拿到的。3、拿到MapperProxy,執行Dao的方法會被MapperProxy的Invoke方法攔截,這里和Mybatis是一樣的。4、這里的Invoke方法攔截后,是轉到了SqlSessionTemplate,由SqlSessionTemplate的屬性sqlSessionProxy
執行sql5、在sqlSessionProxy里面也有一個Invoke方法,里面進一步對事物的進行了封裝。6、整個過程,進了【2個不同的Invoke方法】,這就是Spring實現事務等額外邏輯的處理