Package org.springframework.jdbc.core
Class DataClassRowMapper<T>
java.lang.Object
org.springframework.jdbc.core.BeanPropertyRowMapper<T>
org.springframework.jdbc.core.DataClassRowMapper<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 and may either expose a data class constructor with named
parameters corresponding to column names or classic bean property setters
(or even a combination of both).
Note that this class extends BeanPropertyRowMapper and can
therefore serve as a common choice for any mapped target class, flexibly
adapting to constructor style versus setter methods in the mapped class.
- Since:
- 5.3
- Author:
- Juergen Hoeller
-
Field Summary
Fields inherited from class org.springframework.jdbc.core.BeanPropertyRowMapper
logger -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newDataClassRowMapperfor bean-style configuration.DataClassRowMapper(Class<T> mappedClass) Create a newDataClassRowMapper. -
Method Summary
Modifier and TypeMethodDescriptionprotected TConstruct an instance of the mapped class for the current row.protected voidinitialize(Class<T> mappedClass) Initialize the mapping meta-data for the given class.static <T> DataClassRowMapper<T>newInstance(Class<T> mappedClass) Static factory method to create a newDataClassRowMapper.static <T> DataClassRowMapper<T>newInstance(Class<T> mappedClass, ConversionService conversionService) Static factory method to create a newDataClassRowMapper.Methods inherited from class org.springframework.jdbc.core.BeanPropertyRowMapper
getColumnValue, getColumnValue, getConversionService, getMappedClass, initBeanWrapper, isCheckFullyPopulated, isPrimitivesDefaultedForNullValue, lowerCaseName, mapRow, setCheckFullyPopulated, setConversionService, setMappedClass, setPrimitivesDefaultedForNullValue, suppressProperty, underscoreName
-
Constructor Details
-
DataClassRowMapper
public DataClassRowMapper()Create a newDataClassRowMapperfor bean-style configuration. -
DataClassRowMapper
Create a newDataClassRowMapper.- Parameters:
mappedClass- the class that each row should be mapped to
-
-
Method Details
-
initialize
Description copied from class:BeanPropertyRowMapperInitialize the mapping meta-data for the given class.- Overrides:
initializein classBeanPropertyRowMapper<T>- Parameters:
mappedClass- the mapped class
-
constructMappedInstance
Description copied from class:BeanPropertyRowMapperConstruct an instance of the mapped class for the current row.- Overrides:
constructMappedInstancein classBeanPropertyRowMapper<T>- Parameters:
rs- the ResultSet to map (pre-initialized for the current row)tc- a TypeConverter with this RowMapper's conversion service- Returns:
- a corresponding instance of the mapped class
- Throws:
SQLException- if an SQLException is encountered
-
newInstance
Static factory method to create a newDataClassRowMapper.- Parameters:
mappedClass- the class that each row should be mapped to- See Also:
-
newInstance
public static <T> DataClassRowMapper<T> newInstance(Class<T> mappedClass, @Nullable ConversionService conversionService) Static factory method to create a newDataClassRowMapper.- Parameters:
mappedClass- the class that each row should be mapped toconversionService- theConversionServicefor binding JDBC values to bean properties, ornullfor none- See Also:
-