jdbctemplate在spring2,5中得以简化

http://www.iteye.com/topic/190083
在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

你可能感兴趣的:(java,bean)