本文介绍了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?.

推荐答案

ResultSetExtractor 的JavaDoc:

JavaDoc of ResultSetExtractor:

ResultSetExtractor 假定提取整个ResultSet(可能是多行),而 RowMapper 一次被馈入行.

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之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 19:57