[url]http://www.iteye.com/topic/190083[/url]
在spring2.5以前时使用JdbcTemplate总会被RowMapper所烦恼,比如
现在方便多了,变成这样:
依靠反射漂亮的完成了前段中的bean set
在spring2.5以前时使用JdbcTemplate总会被RowMapper所烦恼,比如
private class JdbcPetRowMapper implements ParameterizedRowMapper<JdbcPet> {
public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
JdbcPet pet = new JdbcPet();
pet.setId(rs.getInt("id"));
pet.setName(rs.getString("name"));
pet.setBirthDate(rs.getDate("birth_date"));
pet.setTypeId(rs.getInt("type_id"));
pet.setOwnerId(rs.getInt("owner_id"));
return pet;
}
}
现在方便多了,变成这样:
this.simpleJdbcTemplate.queryForObject(
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id=?",
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class),
id)
依靠反射漂亮的完成了前段中的bean set