我正在使用 MyBatis 和 Java。我可以在结果映射中使用多个id吗?
代码
我的 Result Java 类如下所示:
public class MyClass {
private int id1;
private int id2;
private int total;
// getters & setters
}
Run Code Online (Sandbox Code Playgroud)
目前,我的 MyBatis 结果图如下所示:
<resultMap id="MyResult" type="MyClass">
<result property="id1" column="id1" />
<result property="id2" column="id2" />
<result property="total" column="total" />
</resultMap>
Run Code Online (Sandbox Code Playgroud)
此结果映射用于此查询:
<select id="mySelect" resultMap="MyResult" parameterType="Map">
select
id1,
id2,
sum(total) as total
from
myTable
group by
id1,id2;
</select>
Run Code Online (Sandbox Code Playgroud)
一切工作正常,但根据 MyBatis 文档,我应该使用id来获得一些效率。我想将 MyBatis 结果映射更改为:
<resultMap id="MyResult" type="MyClass">
<id property="id1" column="id1" />
<id property="id2" column="id2" />
<result property="total" column="total" />
</resultMap>
Run Code Online (Sandbox Code Playgroud)
问题
[稍后编辑]:经过测试,它似乎没有搞乱分组和行,所以我想说它像以前一样工作并且符合预期。
我在哪里查看,但找不到答案
| 归档时间: |
|
| 查看次数: |
4677 次 |
| 最近记录: |