ResultSetExtractor和Rowmapper之间有什么区别? [英] what is difference between ResultSetExtractor vs Rowmapper?

查看:594
本文介绍了ResultSetExtractor和Rowmapper之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在行映射器和结果集提取器回调接口上工作,发现差异,即

I worked on both row mapper and resultset extractor call back interfaces.I found difference i.e.,

1.行映射器可以按行处理.但是结果集提取器可以对所有行进行导航,返回类型为object.

1.Row mapper can be processing per row basis.But Resultset extractor we can naviagte all rows and return type is object.

除了上面还有其他区别吗?.Rowmapper内部和返回类型是list的工作方式.

Is there any difference other than above?.How the works Rowmapper internal and return type is list?.

推荐答案

JavaDoc of ResultSetExtractor:

此接口主要在JDBC框架本身中使用.对于ResultSet处理,RowMapper通常是一个更简单的选择,它为每行映射一个结果对象,而不是为整个ResultSet映射一个结果对象.

This interface is mainly used within the JDBC framework itself. A RowMapper is usually a simpler choice for ResultSet processing, mapping one result object per row instead of one result object for the entire ResultSet.

ResultSetExtractor 假定提取整个ResultSet(可能是多行),而

ResultSetExtractor is suppose to extract the whole ResultSet (possibly multiple rows), while RowMapper is feeded with row at a time.

大多数情况下,ResultSetExtractor将循环ResultSet并使用RowMapper,这是Spring RowMapperResultSetExtractor的片段示例:

Most the time, ResultSetExtractor will loop the ResultSet and use RowMapper, snippet example of Spring RowMapperResultSetExtractor:

List<T> results = (this.rowsExpected > 0 ? new ArrayList<T>(this.rowsExpected) : new ArrayList<T>());
int rowNum = 0;
while (rs.next()) {
    results.add(this.rowMapper.mapRow(rs, rowNum++));
}
return results;

请注意,所有结果都会被转换,这可能会导致内存不足异常.

Pay attention, ALL results will be transformed, this can create Out Of Memory exception.

这篇关于ResultSetExtractor和Rowmapper之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆