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
org.
and is similarly used for org..
DataClassRowMapper, BeanPropertyRowMapper, org.springframework.jdbc.core.simple.JdbcClient.StatementSpec#query(Class) , org.springframework.jdbc.core.namedparam.SimplePropertySqlParameterSource
| Modifier and Type | Field and Description |
|---|---|
| private final String[] | |
| private final TypeDescriptor[] | |
| private final ConversionService | |
| private final Class | |
| private final Constructor | |
| private static final Object | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public | SimplePropertyRowMapper(Class<T>
the class that each row should be mapped to mappedClass)Create a new |
| public | SimplePropertyRowMapper(Class<T>
the class that each row should be mapped to mappedClass, ConversionService a conversionService)ConversionService for binding
JDBC values to bean propertiesCreate a new |
| Modifier and Type | Method and Description |
|---|---|
| private Object | |
| public T | mapRow(ResultSet
the rs, int ResultSet to map (pre-initialized for the current row)the number of the current row rowNumber)Implements org. Implementations must implement this method to map each row of data in the
|
| constructorParameterNames | back to summary |
|---|---|
| private final String[] constructorParameterNames | |
| constructorParameterTypes | back to summary |
|---|---|
| private final TypeDescriptor[] constructorParameterTypes | |
| conversionService | back to summary |
|---|---|
| private final ConversionService conversionService | |
| mappedClass | back to summary |
|---|---|
| private final Class<T> mappedClass | |
| mappedConstructor | back to summary |
|---|---|
| private final Constructor<T> mappedConstructor | |
| NO_DESCRIPTOR | back to summary |
|---|---|
| private static final Object NO_DESCRIPTOR | |
| propertyDescriptors | back to summary |
|---|---|
| private final Map<String, Object> propertyDescriptors | |
| SimplePropertyRowMapper | back to summary |
|---|---|
| public SimplePropertyRowMapper(Class<T> mappedClass) Create a new
| |
| SimplePropertyRowMapper | back to summary |
|---|---|
| public SimplePropertyRowMapper(Class<T> mappedClass, ConversionService conversionService) Create a new
| |
| getDescriptor | back to summary |
|---|---|
| private Object getDescriptor(String column) | |
| mapRow | back to summary |
|---|---|
| public T mapRow(ResultSet rs, int rowNumber) throws SQLException Implements org. Doc from org. Implementations must implement this method to map each row of data in the
| |