【问题标题】:Multiple ids in MyBatis resultMap - performance benefits?MyBatis resultMap 中的多个 id - 性能优势?
【发布时间】:2017-02-26 04:18:15
【问题描述】:

我正在使用带有 Java 的 MyBatis。我可以在结果图中使用多个 id 吗?

代码

我的 Result 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>

问题

  1. 它会像以前一样工作吗?

[稍后编辑]:经过测试,似乎它并没有搞砸分组和行,所以我会说它像以前一样工作并且符合预期。

  1. 使用 id 会带来 MyBatis 的性能优势吗?

我在哪里查找,但找不到答案

  1. MyBatis documentation - 他们没有说或举出类似情况的例子。
  2. Composite Key - 但是,我没有复合键,我宁愿不修改 MyClass 来创建具有 id1、id2 的伪类 ID。

【问题讨论】:

    标签: java mybatis


    【解决方案1】:

    是的,它会像以前一样工作,并且根据文档,它会获得一些效率,当你处理大量行时你会很感激。无论如何,我的建议是使用第二个结果图,以便根据您的数据库结构在定义结果图时最准确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      • 2016-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 1970-01-01
      相关资源
      最近更新 更多