Class SimplePropertyRowMapper<T>
- Type Parameters:
T
- the result type
- All Implemented Interfaces:
RowMapper<T>
RowMapper
implementation that converts a row into a new instance
of the specified mapped target class. The mapped target class must be a
top-level class or static
nested class, and it may expose either a
data class constructor with named parameters corresponding to column
names or classic bean property setter methods with property names corresponding
to column names or fields with corresponding field names.
When combining a data class constructor with setter methods, any property mapped successfully via a constructor argument will not be mapped additionally via a corresponding setter method or field mapping. This means that constructor arguments take precedence over property setter methods which in turn take precedence over direct field mappings.
To facilitate mapping between columns and properties that don't have matching
names, try using underscore-separated column aliases in the SQL statement like
"select fname as first_name from customer"
, where first_name
can be mapped to a setFirstName(String)
method in the target class.
This is a flexible alternative to DataClassRowMapper
and
BeanPropertyRowMapper
for scenarios where no specific customization
and no pre-defined property mappings are needed.
In terms of its fallback property discovery algorithm, this class is similar to
SimplePropertySqlParameterSource
and is similarly used for JdbcClient
.
- Since:
- 6.1
- Author:
- Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorDescriptionSimplePropertyRowMapper
(Class<T> mappedClass) Create a newSimplePropertyRowMapper
.SimplePropertyRowMapper
(Class<T> mappedClass, ConversionService conversionService) Create a newSimplePropertyRowMapper
. -
Method Summary
-
Constructor Details
-
SimplePropertyRowMapper
Create a newSimplePropertyRowMapper
.- Parameters:
mappedClass
- the class that each row should be mapped to
-
SimplePropertyRowMapper
Create a newSimplePropertyRowMapper
.- Parameters:
mappedClass
- the class that each row should be mapped toconversionService
- aConversionService
for binding JDBC values to bean properties
-
-
Method Details
-
mapRow
Description copied from interface:RowMapper
Implementations must implement this method to map each row of data in theResultSet
. This method should not callnext()
on theResultSet
; it is only supposed to map values of the current row.- Specified by:
mapRow
in interfaceRowMapper<T>
- Parameters:
rs
- theResultSet
to map (pre-initialized for the current row)rowNumber
- the number of the current row- Returns:
- the result object for the current row (may be
null
) - Throws:
SQLException
- if an SQLException is encountered while getting column values (that is, there's no need to catch SQLException)
-