Slide 21
Slide 21 text
21
21
Method References with Spring's JdbcTemplate
public List getPersonList(String department) {
JdbcTemplate jt = new JdbcTemplate(this.dataSource);
return jt.query("SELECT name, age FROM person WHERE dep = ?",
ps -> ps.setString(1, "Sales"),
this::mapPerson);
}
private Person mapPerson(ResultSet rs, int rowNum)
throws SQLException {
return new Person(rs.getString(1), rs.getInt(2));
}