Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MyBatis resultMap中的多个ID-性能优势?_Java_Mybatis - Fatal编程技术网

Java MyBatis resultMap中的多个ID-性能优势?

Java MyBatis resultMap中的多个ID-性能优势?,java,mybatis,Java,Mybatis,我将MyBatis与Java一起使用。我可以在结果映射中使用多个ID吗 代码 我的Java类结果如下所示: public class MyClass { private int id1; private int id2; private int total; // getters & setters } <resultMap id="MyResult" type="MyClass"> <result property="id1

我将MyBatis与Java一起使用。我可以在结果映射中使用多个ID吗

代码

我的Java类结果如下所示:

public class MyClass {
    private int id1;
    private int id2;
    private int total;

    // getters & setters
}
<resultMap id="MyResult" type="MyClass">
    <result property="id1" column="id1" />
    <result property="id2" column="id2" />
    <result property="total" column="total" />
</resultMap>
目前,我的MyBatis结果图如下所示:

public class MyClass {
    private int id1;
    private int id2;
    private int total;

    // getters & setters
}
<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>

选择
id1,
id2,
总计
从…起
我的桌子
分组
id1,id2;
一切正常,但根据MyBatis文档,我应该使用id来提高效率。我想将MyBatis结果映射更改为:

<resultMap id="MyResult" type="MyClass">
    <id property="id1" column="id1" />
    <id property="id2" column="id2" />
    <result property="total" column="total" />
</resultMap>

问题

  • 它会像以前一样工作吗
  • [稍后编辑]:经过测试,它似乎没有破坏分组和行,因此我想说,它的工作原理与之前一样,也与预期一样

  • 使用id是否会带来MyBatis的性能优势
  • 我在哪里查找,但找不到答案

  • -他们没有说明或举例说明类似情况
  • -但是,我没有复合密钥,我不希望修改MyClass以创建具有id1、id2的伪类ID

  • 是的,它的工作原理与以前相同,并且根据文档,它将获得一些效率,当您处理大量行时,您将非常欣赏这些效率。无论如何,我建议使用第二个结果映射,以便根据数据库结构最准确地定义结果映射