mybatis 结果集处理
所属分类 mybatis
浏览量 859
结果集两种映射方式 resultType resultMap
applyAutomaticMappings 根据 resultType 自动映射赋值
applyPropertyMappings 根据resultMap 配合赋值
org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(ResultSetWrapper, ResultMap, String)
private Object getRowValue(ResultSetWrapper rsw, ResultMap resultMap, String columnPrefix) throws SQLException {
final ResultLoaderMap lazyLoader = new ResultLoaderMap();
Object rowValue = createResultObject(rsw, resultMap, lazyLoader, columnPrefix);
if (rowValue != null && !hasTypeHandlerForResultObject(rsw, resultMap.getType())) {
final MetaObject metaObject = configuration.newMetaObject(rowValue);
boolean foundValues = this.useConstructorMappings;
if (shouldApplyAutomaticMappings(resultMap, false)) {
foundValues = applyAutomaticMappings(rsw, resultMap, metaObject, columnPrefix) || foundValues;
}
foundValues = applyPropertyMappings(rsw, resultMap, metaObject, lazyLoader, columnPrefix) || foundValues;
foundValues = lazyLoader.size() > 0 || foundValues;
rowValue = foundValues || configuration.isReturnInstanceForEmptyRow() ? rowValue : null;
}
return rowValue;
}
例子代码
https://gitee.com/dyyx/demos/blob/master/mybatis/src/main/java/dyyx/MybatisTest.java
关于sql字段大小写
h2 取值时统一转成大写 ,不同的jdbc驱动实现可能不一样
org.h2.jdbc.JdbcResultSet
private Value get(String columnLabel) {
return get(getColumnIndex(columnLabel));
}
Integer index = columnLabelMap.get(StringUtils.toUpperEnglish(columnLabel));
if (index == null) {
throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
}
return index + 1;
TreeMap key 忽略大小写
mybatis独立使用(不依赖spring)
MySQL jdbc ResultSet
上一篇
下一篇
godoc安装
GO自定义模块实例
GO printf 格式化输出
Mybatis常用工具类
MySQL jdbc ResultSet
key忽略大小写的TreeMap