`

BeanPropertyRowMapper

阅读更多

BeanPropertyRowMapper

 

转自(http://www.blogjava.net/cmzy/archive/2008/09/11/228271.html

 

今天看SpringAPI的时候无意中发现了Spring2.5新增了一个RowMapper的实现类org.springframework.jdbc.core.BeanPropertyRowMapper,但是貌似Springrefrence里面根本就没提及到。Google了一下……貌似也莫得多少文档。

 

Spring API Doc的说明如下:

 

RowMapper implementation that converts a row into a new instance of the specified mapped target class. The mapped target class must be a top-level class and it must have a default or no-arg constructor.

 

Column values are mapped based on matching the column name as obtained from result set metadata to public setters for the corresponding properties. The names are matched either directly or by transforming a name separating the parts with underscores to the same name using "camel" case.

 

Mapping is provided for fields in the target class for many common types, e.g.: String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long, float, Float, double, Double, BigDecimal, java.util.Date, etc.

 

To facilitate mapping between columns and fields that don't have matching names, try using column aliases in the SQL statement like "select fname as first_name from customer".

 

Please note that this class is designed to provide convenience rather than high performance. For best performance consider using a custom RowMapper.

 

也就说,它可以把ResultSet和实体类的字段进行实现自动映射。

分享到:
评论

相关推荐

    使用Spring的JdbcTemplate和BeanPropertyRowMapper完成的JDBC

    使用Spring的JdbcTemplate和BeanPropertyRowMapper完成的JDBC我的实例 博文链接:https://zmx.iteye.com/blog/373454

    JdbcTemplateTool.zip

    又比如JdbcTemplate 可以帮忙把一个查询结果传化为一个对象列表,但是你需要查阅一些资料才知道要用 BeanPropertyRowMapper 。如果下次要用的时候又忘记了这个类,又要查一次或者翻以前的代码来看,其实完全可以提供...

    实现Mybatis框架中一对多关联映射的查询操作。

    实现Mybatis框架中一对多关联映射的查询操作。 User用户表 - Order_form订单表属于 1-N 的关系。 一个用户对象包含一批订单信息

    JdbcTemplate的jar包.rar

    查询所有的内容,封装为对象用:template.query(sql, new BeanPropertyRowMapper<对象>(对象.class)); 查询需要使用聚合函数的内容,如:select count(id)from account用:template.queryForObject(sql)

    jdbcTemplate

    List<User> userList = getJdbcTemplate().query(sql, new BeanPropertyRowMapper(User.class), primaryKeyId); if(userList.size() == 0) { return null; } return userList.get(0); } @Override public ...

    JDBC Template源码.7z

    JDBCTemp+MySQL示例。Spring,PropertyPlaceholderConfigurer,BeanPropertyRowMapper

Global site tag (gtag.js) - Google Analytics