看下执行下面这行代码的时候,都发生了什么
User user = userMapper.getById(1L);
在上一篇中,获取mapper其实是以org.apache.ibatis.binding.MapperProxy为InvocationHandler创建代理对象。那么执行接口的方法的时候,也应该是执行MapperProxy的invoke方法
org.apache.ibatis.binding.MapperProxy#invoke
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 (isDefaultMethod(method)) {
return invokeDefaultMethod(proxy, method, args);
}
} catch (Throwable t) {
throw ExceptionUtil.unwrapThrowable(t);
}
//封装下method成MapperMethod
final MapperMethod mapperMethod = cachedMapperMethod(method);
return mapperMethod.execute(sqlSession, args);
}
org.apache.ibatis.binding.MapperMethod#execute 根据查询的类型不同执行不同的方法,执行select的时候还要根据不同的返回值类型执行不同的方法
p