类 ColumnMapRowMapper
- java.lang.Object
- org.springframework.jdbc.core.ColumnMapRowMapper
public class ColumnMapRowMapper extends Object implements RowMapper<Map<String,Object>>
RowMapper
implementation that creates ajava.util.Map
for each row, representing all columns as key-value pairs: one entry for each column, with the column name as key.The Map implementation to use and the key to use for each column in the column Map can be customized through overriding
createColumnMap(int)
andgetColumnKey(java.lang.String)
, respectively.Note: By default, ColumnMapRowMapper will try to build a linked Map with case-insensitive keys, to preserve column order as well as allow any casing to be used for column names. This requires Commons Collections on the classpath (which will be autodetected). Else, the fallback is a standard linked HashMap, which will still preserve column order but requires the application to specify the column names in the same casing as exposed by the driver.
- 从以下版本开始:
- 1.2
- 作者:
- Juergen Hoeller
- 另请参阅:
JdbcTemplate.queryForList(String)
,JdbcTemplate.queryForMap(String)
构造器概要
构造器 构造器 说明 ColumnMapRowMapper()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Map<String,Object>
createColumnMap(int columnCount)
Create a Map instance to be used as column map.protected String
getColumnKey(String columnName)
Determine the key to use for the given column in the column Map.protected Object
getColumnValue(ResultSet rs, int index)
Retrieve a JDBC object value for the specified column.Map<String,Object>
mapRow(ResultSet rs, int rowNum)
Implementations must implement this method to map each row of data in the ResultSet.
构造器详细资料
ColumnMapRowMapper
public ColumnMapRowMapper()
方法详细资料
mapRow
public Map<String,Object> mapRow(ResultSet rs, int rowNum) throws SQLException
从接口复制的说明:RowMapper
Implementations must implement this method to map each row of data in the ResultSet. This method should not callnext()
on the ResultSet; it is only supposed to map values of the current row.- 指定者:
mapRow
在接口中RowMapper<Map<String,Object>>
- 参数:
rs
- the ResultSet to map (pre-initialized for the current row)rowNum
- the number of the current row- 返回:
- the result object for the current row (may be
null
) - 抛出:
SQLException
- if an SQLException is encountered getting column values (that is, there's no need to catch SQLException)
createColumnMap
protected Map<String,Object> createColumnMap(int columnCount)
Create a Map instance to be used as column map.By default, a linked case-insensitive Map will be created.
- 参数:
columnCount
- the column count, to be used as initial capacity for the Map- 返回:
- the new Map instance
- 另请参阅:
LinkedCaseInsensitiveMap
getColumnKey
protected String getColumnKey(String columnName)
Determine the key to use for the given column in the column Map.- 参数:
columnName
- the column name as returned by the ResultSet- 返回:
- the column key to use
- 另请参阅:
ResultSetMetaData.getColumnName(int)
getColumnValue
@Nullable protected Object getColumnValue(ResultSet rs, int index) throws SQLException
Retrieve a JDBC object value for the specified column.The default implementation uses the
getObject
method. Additionally, this implementation includes a "hack" to get around Oracle returning a non standard object for their TIMESTAMP datatype.- 参数:
rs
- is the ResultSet holding the dataindex
- is the column index- 返回:
- the Object returned
- 抛出:
SQLException
- 另请参阅:
JdbcUtils.getResultSetValue(java.sql.ResultSet, int, java.lang.Class<?>)