executeWithResultHandler(sqlSession, args); result = null; } else if (method.returnsMan。Mybatis是如何执行一条SQL命令的( 二 )。" />

Mybatis是如何执行一条SQL命令的( 二 )


} else if (SqlCommandType.SELECT == command.getType()) {
if (method.returnsVoid()--tt-darkmode-color: #FFFFFF;"> executeWithResultHandler(sqlSession, args);
result = null;
} else if (method.returnsMany()) {
result = executeForMany(sqlSession, args);
} else if (method.returnsMap()) {
result = executeForMap(sqlSession, args);
} else {
Object param = method.convertArgsToSqlCommandParam(args);
result = sqlSession.selectOne(command.getName(), param);
}
} else if (SqlCommandType.FLUSH == command.getType()) {
result = sqlSession.flushStatements();
} else {
throw new BindingException("Unknown execution method for: " + command.getName());
}
if (result == null--tt-darkmode-color: #FFFFFF;"> throw new BindingException("Mapper method '" + command.getName()
+ " attempted to return null from a method with a primitive return type (" + method.getReturnType() + ").");
}
return result;
}
org.apache.ibatis.binding.MapperMethod.SqlCommand 。
public static class SqlCommand {
// full id, 通过它可以找到MappedStatement
private final String name;
private final SqlCommandType type;
org.apache.ibatis.binding.MapperMethod.MethodSignature:
public static class MethodSignature {
private final boolean returnsMany;
private final boolean returnsMap;
private final boolean returnsVoid;
private final Class returnType;
【Mybatis是如何执行一条SQL命令的】 private final String mapKey;
private final Integer resultHandlerIndex;
private final Integer rowBoundsIndex;
private final SortedMap params;
private final boolean hasNamedParameters;
public MethodSignature(Configuration configuration, Method method) {
this.returnType = method.getReturnType();
this.returnsVoid = void.class.equals(this.returnType);
this.returnsMany = (configuration.getObjectFactory().isCollection(this.returnType) || this.returnType.isArray());
this.mapKey = getMapKey(method);
this.returnsMap = (this.mapKey != null);
this.hasNamedParameters = hasNamedParams(method);
// 分页参数
this.rowBoundsIndex = getUniqueParamIndex(method, RowBounds.class);
// 自定义ResultHandler
this.resultHandlerIndex = getUniqueParamIndex(method, ResultHandler.class);
this.params = Collections.unmodifiableSortedMap(getParams(method, this.hasNamedParameters));
}
以上是对MapperMethod的补充说明 。


推荐阅读