Class SimplePropertyRowMapper<T>

Type Parameters:
T - the result type
All Implemented Interfaces:

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.

Juergen Hoeller
See Also:
  • Constructor Details

    • SimplePropertyRowMapper

      public SimplePropertyRowMapper(Class<T> mappedClass)
      Create a new SimplePropertyRowMapper.
      mappedClass - the class that each row should be mapped to
    • SimplePropertyRowMapper

      public SimplePropertyRowMapper(Class<T> mappedClass, ConversionService conversionService)
      Create a new SimplePropertyRowMapper.
      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>
      rs - the ResultSet to map (pre-initialized for the current row)
      rowNumber - the number of the current row
      the result object for the current row (may be null)
      SQLException - if an SQLException is encountered while getting column values (that is, there's no need to catch SQLException)