Why Not BeanPropertyRowMapper?

First, the performance of BeanPropertyRowMapper is abysmal, as it says in the doc it’s not made for that. This module offers performance very close to a manually written RowMapper - it could even be faster as name access to a column is more expensive than by index.

Second SimpleFlatMapper support constructor injection, factory method, deep object etc…

Third, it also supports SqlParameterSource, and Crud operations.

You might also have a look at Spring-JDBC-ROMA that also creates RowMapper.

Getting Started Spring jdbc

Maven Central JavaDoc

Setting up the environment

Add the Dependency to your build.

for Maven:

Java 8

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-springjdbc</artifactId>
    <version>3.13.2</version>
</dependency>

Java 6, 7

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-springjdbc</artifactId>
    <version>3.13.2</version>
    <classifier>jdk16</classifier>
</dependency>

Java 9

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-springjdbc</artifactId>
    <version>3.13.2</version>
    <classifier>jdk9ea</classifier>
</dependency>

RowMapper

class MyDao {
    private final RowMapper<DbObject> rowMapper =
        JdbcTemplateMapperFactory.newInstance().newRowMapper(DbObject.class);
        
    public List<DbObject> findAll() {
        return template.query(DbHelper.TEST_DB_OBJECT_QUERY, rowMapper);
    }
}

SqlParameterSource

class MyDao {
    private final SqlParameterSourceFactory<DbObject> parameterSourceFactory =
        JdbcTemplateMapperFactory
            .newInstance()
            .newSqlParameterSourceFactory(DbObject.class);

    public void insertObject(DbObject object) {
        template.update(
            "INSERT INTO DBOBJECTS(id, name, email)"
            + " VALUES(:id, :name, :email)",
            parameterSourceFactory.newSqlParameterSource(object));

    }

    public void insertObjects(Collection<DbObject> objects) {
        template.batchUpdate(
            "INSERT INTO DBOBJECTS(id, name, email)"
            + "VALUES(:id, :name, :email)",
            parameterSourceFactory.newSqlParameterSources(objects));
    }
}

Crud

class MyDao {

    JdbcTemplateCrud<DbObject, Long> objectCrud;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        objectCrud =
            JdbcTemplateMapperFactory
                .newInstance()
                .<DbObject, Long>crud(DbObject.class, Long.class)
                .to(template, "TEST_DB_OBJECT");
    }

    public void insertObject(DbObject object) {
        crud.create(object);
    }

    public void insertObjects(Collection<DbObject> objects) {
        crud.create(objects);
    }
}

More examples

See JdbcTemplateMapperFactoryTest for more examples.