Package org.springframework.jdbc.core

# Class SimplePropertyRowMapper<T>

java.lang.Object
org.springframework.jdbc.core.SimplePropertyRowMapper<T>

Type Parameters:
  `T` - the result type

All Implemented Interfaces:
  `RowMapper<T>`

public class SimplePropertyRowMapper<T> extends Object implements 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:
  - `DataClassRowMapper`
  - `BeanPropertyRowMapper`
  - `JdbcClient.StatementSpec.query(Class)`
  - `SimplePropertySqlParameterSource`

## Constructor Summary

Constructors
Constructor
Description
`SimplePropertyRowMapper(Class<T> mappedClass)`
Create a new `SimplePropertyRowMapper`.
`SimplePropertyRowMapper(Class<T> mappedClass, org.springframework.core.convert.ConversionService conversionService)`
Create a new `SimplePropertyRowMapper`.

## Method Summary

Modifier and Type
Method
Description
`T`
`mapRow(ResultSet rs, int rowNumber)`
Implementations must implement this method to map each row of data in the `ResultSet`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SimplePropertyRowMapper

public SimplePropertyRowMapper(Class<T> mappedClass)
Create a new `SimplePropertyRowMapper`.

Parameters:
  `mappedClass` - the class that each row should be mapped to

### SimplePropertyRowMapper

public SimplePropertyRowMapper(Class<T> mappedClass, org.springframework.core.convert.ConversionService conversionService)
Create a new `SimplePropertyRowMapper`.

Parameters:
  `mappedClass` - the class that each row should be mapped to
  `conversionService` - a `ConversionService` for binding JDBC values to bean properties

## Method Details

### mapRow

public T mapRow(ResultSet rs, int rowNumber) throws SQLException
Description copied from interface: `RowMapper`
Implementations must implement this method to map each row of data in the `ResultSet`. This method should not call `next()` on the `ResultSet`; it is only supposed to map values of the current row.

Specified by:
  `mapRow` in interface `RowMapper<T>`
Parameters:
  `rs` - the `ResultSet` 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)