Mybatis原理

Catalogue
  1. 查询流程
  2. SqlSession

查询流程

其中的一个UserMapper的实例为:

1
com.baomidou.mybatisplus.core.override.MybatisMapperProxy@13250132

动态代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
MybatisMapperProxy implements InvocationHandler{

// invoke 方法.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
if (Object.class.equals(method.getDeclaringClass())) {
return method.invoke(this, args);
} else if (method.isDefault()) {
if (privateLookupInMethod == null) {
return invokeDefaultMethodJava8(proxy, method, args);
} else {
return invokeDefaultMethodJava9(proxy, method, args);
}
}
} catch (Throwable t) {
throw ExceptionUtil.unwrapThrowable(t);
}
final MybatisMapperMethod mapperMethod = cachedMapperMethod(method);
return mapperMethod.execute(sqlSession, args);
}
}

不需要所有的map都写到一个项目中。

kits只是集成了数据访问,方便的数据访问开发。 然后各自的map集成到各自的项目中去。

SqlSession

主要是sqlSession操作数据库,增删改查。

实现有SqlSessionTemplate,SqlSessionManager,DefaultSqlSession.