`
阅读更多
Proper Usage of remapResults="true"
The remapResults attribute is available on 【statement】, 【select】, and 【procedure】 mapped statements. It is an optional attribute and the default value is false.

The remapResults attribute should be set to true when a query has a variable set of return columns. For example, consider the following queries:

在 【statement】, 【select】, 和【procedure】 标签中存在一个可选的属性【remapResults】,默认值是false.
如果每次查询的列不定的话,这个属性需要设置为true.如下所例:

xml 代码
SELECT $fieldList$   
  FROM table  
In this example, the list of column names is dynamic, even though the table is always the same.
在这个例子中,虽然检索的是同一张表,可是每次查询的列却是可变的。
xml 代码
SELECT *   
  FROM $someTable$  

In this example, the table could be different. Because of the usage of * in the SELECT clause, the resulting columns names could be different, as well.
在这个例子中,因为在Select中使用了*匹配符,所以查询的列会随着表名的不同而发生变化。

Since the overhead to introspect the result set metadata is not trivial, iBATIS will remember what was returned the last time the query was run. This could create problems in situations similar to the examples above.
为了避免经常的对返回的结果进行内省,iBATIS会记录上一次查询结果的元数据,这样,在遇到上面的例子时就会出现问题。




--------------------------------------------------------------------------------



Let's consider what iBATIS will do for the first example depending on the usage of remapResults.

让我们了解一下,iBATIS是如何依赖remapResults属性的。

Without remapResults, or remapResults="false":

当没有设置remapResults属性,或者设置remapResults为false时:

Let's say $fieldList$ is set to "fld1, fld2" the first time the query is executed, thus giving the query:
假设在第一次查询时,$fieldList$设置为"fld1, fld2" ,查询语句等效下面的SQL:

xml 代码
SELECT fld1, fld2   
  FROM table  

iBATIS will try to be efficient by assuming that fld1 and fld2 will always be in the result set on each subsequent execution of the query.
The application will run into trouble if the value for $fieldList$ changes, such as "fld3, fld4". Not only will iBATIS be unable to find fld1 and fld2 in the result set,
thus returning improper results, iBATIS won't know about fld3 and fld4 because they weren't in the query on its initial execution.

iBATIS为了效率,假设这条SQL语句今后的查询结果都会返回fld1和fld2列。
如果后面$fieldList$发生变化,比如设置为 "fld3, fld4",程序将会遇到一些麻烦。不仅仅是iBATIS找不到fld1和fld2列那么简单,
麻烦的是,iBATIS也不会识别fld3和fld4,因为在SQL初始化的时候,这两列并没有包括在内。

With remapResults="true":

iBATIS will introspect the result set metadata every time the query is run and will always return the proper results. This feature comes at some performance cost, so only use it if you really need it – when the columns in the result set are variable, either directly, like in the first example, or indirectly, because of a variable table.

当设置remapResults为"true"时:
iBATIS会在每次查询的时候内省查询结果来设置元数据,来保证返回恰当的结果。这个属性会造成一定的性能损失,所以要谨慎使用,只在你需要的时候使用--查询列发生变化,直接的,如第一个例子一样,或者隐含的,如第二个例子,检索的表发生变化。
原文: http://www.iteye.com/topic/39367
分享到:
评论

相关推荐

    freemark与ibatis动态运用与说明,程序,源代码,文档

    freemark与ibatis动态运用与说明,程序,源代码,文档

    ibatis例子,很好的

    ibatis运用例子,适用于初学者,很好的,很好的

    IBATIS建立的数据库连接

    运用IBATIS在三层架构的基础上建立的数据库连接,主要是一个框架,突出重点,一看就明白。最适合初学者快速学习使用,里面的条路清晰。

    Struts2+spring+ibatis三大框架整合实例

    项目需要,可直接拿来用。本人花了一个礼拜心血搞的。有点,如果是发布到tomcat55上面可能要删掉验证xml的jar包才能正确运行

    ibatis 环境搭建

    这个是ibatis的简单运用搭建环境,里面有数据库表都写好了 。里面还写了一个查询的方法。你只要想数据库增加值,就可以查询出来

    struts2_spring_ibatis整合源代码

    利用Struts2+Spring+Ibatis来整合开发,使用过struts+spring+...而spring在项目中运用了依赖注入的方式,当然ibatis的持久层比hibernate更能控制SQL语句。感兴趣的学友门将SSI2源代码共享给大家,希望能够帮助到你们!

    struts2+spring+ibatis

    简单的图书管理系统,运用了struts+sping+ibatis的整合,对图书馆进行简单的增,删,改,查功能,数据库采用mysql

    ibatis对数据库进行增删改查操作的小例子

    一个关于ibatis对数据库进行增删改查操作的小例子,简单易学,方便大家快速掌握和运用。

    springMVC+ibatis+jstl+easyui+comet4j

    使用springMvc为框架基础结合ibatis作为持久层,easyui作为前台框架并运用了jstl的标签库,加入了comet4j来实现实时推送

    经典设计模式讲解以及项目实战(Java版)

    本文工程主要计划以下几大块,希望大家也可以一起加入进来,扩大Java设计模式这块的运用场景的提炼。 设计模式简介:主要...Ibatis设计模式简介:主要是讲述Ibatis源码中运用到的一些设计模式(将来增加) 分享说明

    ibatis 学习教程

    很实用的教程 例子简单易懂 深入浅出的分析了其运用的原理

    Java 经典设计模式讲解以及项目实战

    Ibatis设计模式简介:主要是讲述Ibatis源码中运用到的一些设计模式 设计模式简介 1 单例模式 2 责任链模式 3 策略模式 4 模板方法模式 5 工厂方法模式 6 抽象工厂模式 7 建造者模式 8 代理模式 9 装饰模式 10 原型...

    Java扩大Java设计模式

    为了更系统的学习设计模式,特地开了这样一个基于Java的设计模式【集中营】,都是笔者在实际工作中用到过或者学习过的一些设计模式的一些提炼...4. Ibatis设计模式简介:主要是讲述Ibatis源码中运用到的一些设计模式

    免费开源!!经典设计模式讲解以及项目实战(Java版)

    为了更系统的学习设计模式,特地开辟了这样一个基于Java的设计模式【一些集中营】,都是作者在实际工作中用到或者学习过的设计模式的...Ibatis设计模式简介:主要是讲述Ibatis源码中运用到的一些设计模式(未来增加)

    ibatis2讲义

    mybatis2 方方面面,条分缕析的详细讲解了mybatis2的概念,优点与不足,与其他框架做出对比,说明运用场景,更难得的是详细的介绍了每一个知识点的细节,并列举了许多代码示例,帮助学员深入透彻理解mybatis2框架。

    DesignPatterns:经典设计模式讲解以及项目实战(Java版)

    主要介绍各种设计模式的概念和运用场景等设计模式综合运用:主要是笔者在实际工作中运用到的一些设计模式综合运用事例的提炼Spring设计模式简介:主要是讲述Spring源码中运用到的一些设计模式(将来增加)Ibatis设计...

    ssi开发案例

    运用struts、spring和ibatis做的小案例,对java开发的你起到帮助

Global site tag (gtag.js) - Google Analytics