Skip to content
Ameen Abozaid
Planned lessonJNR-026-L03

Mapping rows

  • Lesson 3 of 5
  • Junior
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_at matches createdAt).
  • Write a mapper when types need conversion, for example timestamptz to Instant.
  • Keep mapping inside the repository; services never see ResultSet.
Draft outline details

Demonstration

java
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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.