合理运用remapResults属性
假设在第一次查询时,$fieldList$设置为"fld1, fld2" ,查询语句等效下面的SQL:
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会在每次查询的时候内省查询结果来设置元数据,来保证返回恰当的结果。这个属性会造成一定的性能损失,所以要谨慎使用,只在你需要的时候使用--查询列发生变化,直接的,如第一个例子一样,或者隐含的,如第二个例子,检索的表发生变化。