5

MyBatis源码学习笔记一

 3 years ago
source link: https://segmentfault.com/a/1190000040399451
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

mybatis的创建SqlSession的过程:

image.png

Mybatis使用代理Dao的执行过程:

Mybatis只需提供一个Dao接口,就可以实现与数据库的CRUD交互,这种情形,我们很容易想到用JDK动态代理去实现,事实上也确实如此。
客户端是通过拿到Mybatis提供的Dao接口的代理对象,来进行CRUD操作,过程如下:
image.png

我们直接去看下

  public T newInstance(SqlSession sqlSession) {
    final MapperProxy<T> mapperProxy = new MapperProxy<T>(sqlSession, mapperInterface, methodCache);
    return newInstance(mapperProxy);
  }
  @SuppressWarnings("unchecked")
  protected T newInstance(MapperProxy<T> mapperProxy) {
    return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[] { mapperInterface }, mapperProxy);
  }

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK