锁定老帖子 主题:合理运用remapResults属性
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2006-12-16
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. xml 代码
在这个例子中,虽然检索的是同一张表,可是每次查询的列却是可变的。 xml 代码
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. 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.
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: xml 代码
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. iBATIS为了效率,假设这条SQL语句今后的查询结果都会返回fld1和fld2列。 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"时: 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 10210 次