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
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的补充说明 。
推荐阅读
- 大一非计算机专业的学生,如何利用寒假自学C语言
- 红米K40渲染图曝光:居中挖孔+后置四摄,这外观你觉得如何?
- 奋斗|该如何看待拼多多员工猝死:鼓励奋斗,也要保护好奋斗者
- 装机点不亮 如何简易排查硬件问题?
- 虾米音乐宣布关停!我的歌单如何导入QQ音乐、网易云音乐?
- 人脸识别设备主板如何选型 软硬整合大幅缩短开发时间
- 高通公司宣布任命安蒙为候任首席执行官
- Mini-LED产品效果究竟如何?
- 专家介绍如何判断智能手机被入侵:运行速度变慢、电池消耗过快以及卡顿
- 最便宜的骁龙888手机?红米K40曝光:这外观如何?