接口 RowMapper<T>
- 类型参数:
T
- the result type
- 所有已知实现类:
BeanPropertyRowMapper
,ColumnMapRowMapper
,MappingSqlQueryWithParameters.RowMapperImpl
,SingleColumnRowMapper
,UpdatableSqlQuery.RowMapperImpl
- 函数接口:
- 这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。
@FunctionalInterface public interface RowMapper<T>
An interface used byJdbcTemplate
for mapping rows of aResultSet
on a per-row basis. Implementations of this interface perform the actual work of mapping each row to a result object, but don't need to worry about exception handling.SQLExceptions
will be caught and handled by the calling JdbcTemplate.Typically used either for
JdbcTemplate
's query methods or for out parameters of stored procedures. RowMapper objects are typically stateless and thus reusable; they are an ideal choice for implementing row-mapping logic in a single place.Alternatively, consider subclassing
MappingSqlQuery
from thejdbc.object
package: Instead of working with separate JdbcTemplate and RowMapper objects, you can build executable query objects (containing row-mapping logic) in that style.- 作者:
- Thomas Risberg, Juergen Hoeller
- 另请参阅:
JdbcTemplate
,RowCallbackHandler
,ResultSetExtractor
,MappingSqlQuery
方法详细资料
mapRow
@Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException
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.- 参数:
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)