上一篇 <<<sqlSession如何获得具体的Mapper接口信息
下一篇 >>>sqlSession.selectOne底层实现原理
userMapper实际代理类:org.apache.ibatis.binding.MapperProxy@279ad2e3
代理层实现
if (Object.class.equals(method.getDeclaringClass())) {
//如果是实现类,则直接调用
try {
return method.invoke(this, args);
} catch (Throwable var5) {
throw ExceptionUtil.unwrapThrowable(var5);
}
} else {
//接口层走这里
MapperMethod mapperMethod = MapperProxy.cachedMapperMethod(method);
{
mapperMethod = new MapperMethod(MapperProxy.mapperInterface, method, MapperProxy.sqlSession.getConfiguration());
MapperMethod.command = new MapperMethod.SqlCommand(config, mapperInterface, method);
--configuration.getMappedStatement(statementName); 从config中获取执行的语句ID和内容
MapperMethod.method = new MapperMethod.MethodSignature(config, method);
//做好缓存
MapperProxy.methodCache.put(method, mapperMethod);
method:public abstract com.jgspx.entity.UserEntity com.jgspx.mapper.UserMapper.getUser(int)
}
return mapperMethod.execute(this.sqlSession, args);
}
execute真实操作
判断类型并执行具体的sql语句
if (SqlCommandType.INSERT == this.command.getType()) {
}else if (SqlCommandType.SELECT == this.command.getType()) {
if (this.method.returnsVoid() && this.method.hasResultHandler()) {
this.executeWithResultHandler(sqlSession, args);
result = null;
} else if (this.method.returnsMany()) {
result = this.executeForMany(sqlSession, args);
} else if (this.method.returnsMap()) {
result = this.executeForMap(sqlSession, args);
} else {
param = this.method.convertArgsToSqlCommandParam(args);
result = sqlSession.selectOne(this.command.getName(), param);
name:com.jarye.mapper.UserMapper.getUser
}
推荐阅读:
<<<Mybatis的整体执行原理图解
<<<SqlSessionFactory的创建过程原理
<<<SqlSession的创建过程
<<<sqlSession如何获得具体的Mapper接口信息
<<<sqlSession.selectOne底层实现原理
<<<Mybatis一级缓存知识汇总
<<<Mybatis二级缓存知识汇总
<<<Springboot整合Mybatis二级缓存
<<<Mybatis常见面试题
网友评论