![](/img/trans.png)
[英]How to Reuse ResultMap in Mybatis in multiple Mapper.xml in association?
[英]Multiple ids in MyBatis resultMap - performance benefits?
我正在使用MyBatis和Java。 我可以在結果圖中使用多個ID嗎?
碼
我的結果Java類看起來像這樣:
public class MyClass {
private int id1;
private int id2;
private int total;
// getters & setters
}
目前,我的MyBatis結果圖如下所示:
<resultMap id="MyResult" type="MyClass">
<result property="id1" column="id1" />
<result property="id2" column="id2" />
<result property="total" column="total" />
</resultMap>
此查詢中使用此結果映射:
<select id="mySelect" resultMap="MyResult" parameterType="Map">
select
id1,
id2,
sum(total) as total
from
myTable
group by
id1,id2;
</select>
一切正常,但根據MyBatis文檔,我應該使用id來獲得一些效率。 我想將MyBatis結果映射更改為:
<resultMap id="MyResult" type="MyClass">
<id property="id1" column="id1" />
<id property="id2" column="id2" />
<result property="total" column="total" />
</resultMap>
問題
[稍后編輯]:測試過,似乎它沒有搞砸分組和行,所以我會說它像以前一樣工作並且如預期的那樣。
我在哪里看,但找不到答案
是的,它將像以前一樣工作,並且根據文檔,它將獲得一些效率,當您處理大量行時,您將會欣賞。 無論如何,我的建議是使用第二個結果圖,以便根據您的數據庫結構在結果圖的定義中最准確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.