<dependency>
<groupId>org.simpleflatmapper</groupId>
<artifactId>sfm-springjdbc</artifactId>
<version>2.9.1</version>
</dependency>
See JdbcTemplateMapperFactoryTest for more examples.
class MyDao {
private final RowMapper<DbObject> mapper =
JdbcTemplateMapperFactory.newInstance().newRowMapper(DbObject.class);
public void doSomething() {
List<DbObject> results = template.query(DbHelper.TEST_DB_OBJECT_QUERY, mapper);
}
public void doSomethingElse() {
template
.query(TEST_DB_OBJECT_QUERY,
mapper.newResultSetExtractor((o) -> System.out.println(o.toString())));
}
}
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));
}
}
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);
}
}