userMapper.getUser(1);底层实现原理

上一篇 << 下一篇 >>>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
    }

推荐阅读:
<< << << << << << << << << <<

你可能感兴趣的:(userMapper.getUser(1);底层实现原理)