Mapping rows
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
turn result rows into records.
Planned topics
- A
RowMapper<T>converts one row to one object; Spring loops over the rows. - You never call
rs.next()yourself. query(Product.class)maps columns to record components or properties automatically (names must match;created_atmatchescreatedAt).- Write a mapper when types need conversion, for example
timestamptztoInstant. - Keep mapping inside the repository; services never see
ResultSet.
Draft outline details
Demonstration
private static final RowMapper<Product> MAPPER = (rs, i) -> new Product(
rs.getLong("id"),
rs.getString("name"),
rs.getBigDecimal("price"));Check your understanding
Who calls rs.next() when you use a RowMapper?
Show answer
Spring.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.