Spring JdbcTemplate RowMapper vs ResultSetExtractor
来源:互联网 发布:华为性格测试 知乎 编辑:程序博客网 时间:2024/06/06 20:05
RowMapper interface allows to map a row of the relations with the instance of user-defined class. It iterates the ResultSet internally and adds it into the collection. So we don't need to write a lot of code to fetch the records as ResultSetExtractor.
Example Comparision
ResultSetExtractor : need to manually create a collection(list) to instore the extract data
public List<Product> getAllProducts(){String sql = "select * from product";return jdbcTemplate.query(sql, new ResultSetExtractor<List<Product>>(){@Overridepublic List<Product> extractData(ResultSet rs)throws SQLException, DataAccessException {List<Product> list = new ArrayList<Product>();while (rs.next()) {Product product = new Product();product.setId(rs.getString(1));product.setName(rs.getString(2));product.setPrice(rs.getFloat(3));list.add(product);}return list;}});}
RowMapper : internally adds the data of ResultSet into the collection
public List<Product> getAllProductsRowMapper(){String sql = "select * from product";return jdbcTemplate.query(sql, new RowMapper<Product>(){@Overridepublic Product mapRow(ResultSet rs, int rowNumber) throws SQLException {Product p = new Product();p.setId(rs.getString(1));p.setName(rs.getString(2));p.setPrice(rs.getFloat(3));return p;}});}
0 0
- Spring JdbcTemplate RowMapper vs ResultSetExtractor
- spring jdbctemplate三种常见回调RowMapper,RowCallbackHandler,ResultSetExtractor
- Spring中JdbcTemplate中使用RowMapper
- Spring中JdbcTemplate中使用RowMapper
- 在Spring中JdbcTemplate中使用RowMapper
- Spring JdbcTemplate 查询方法中的RowMapper实现汇总
- Spring 使用JdbcTemplate类实现批量查询(RowMapper)
- Spring JdbcTemplate 查询方法中的RowMapper实现汇总
- Spring中JdbcTemplate使用RowMapper(简单明了的代码)
- Spring JdbcTemplate RowCallbackHandler和RowMapper<T>的比较
- jdbcTemplate中 RowMapper使用
- Spring-RowMapper
- Spring-RowMapper
- Spring-RowMapper
- Spring--RowMapper
- Spring JdbcTemplate 查询方法中的RowMapper实现汇总_再回首_百度空间
- Spring使用JdbcTemplate实现对数据库操作 (内部类定义RowMapper)
- JdbcTemplate中RowMapper的粗浅理解
- linux目录结构
- 被Unable to compile class for jsp搞疯了
- 如何在PowerShell中用replace巧妙地替换字符串
- 2015061408 - 规划一个人生?
- HDU 1134 卡特兰数 大数乘法除法
- Spring JdbcTemplate RowMapper vs ResultSetExtractor
- c语言的冒泡排序
- <一> Linux是什么
- Linux添加 用户
- Functional MRI (second edition) -- 1. An introduction to fMRI
- matlab pca 函数 输入输出数据的意义
- 2015061409 - 怎么看公司给新员工的薪水高于老员工的薪水?
- spark入门讲座
- 关于“接口”的理解