【发布时间】:2018-02-11 08:04:12
【问题描述】:
我做了很多研究,但无济于事。在 Mybatis 文档中,它说
id – 一个 ID 结果;将结果标记为 ID 将有助于提高整体性能
result - 注入到字段或 JavaBean 属性中的正常结果
如果它们都可以注入到一个字段中,并且 id 具有性能改进,那么是什么阻止我完全不使用 id 呢?这只是我将主键映射到 id 标签的语义吗?
我试过了:
<resultMap id="teacherMap" type="me.funmap.model.Teacher" autoMapping="true">
<result column="t_id" property="t_id"/>
<collection property="students" javaType="List" ofType="me.funmap.model.Student" autoMapping="true">
<result column="s_id" property="s_id"/>
</collection>
</resultMap>
和
<resultMap id="teacherMap" type="me.funmap.model.Teacher" autoMapping="true">
<id column="t_id" property="t_id"/>
<collection property="students" javaType="List" ofType="me.funmap.model.Student" autoMapping="true">
<id column="s_id" property="s_id"/>
</collection>
</resultMap>
声明
<select id="getAllTeacher" resultMap="teacherMap">
SELECT teacher.t_id, t_name, s_id from teacher INNER JOIN student ON teacher.t_id = student.t_id
</select>
陈述结果
t_id t_name s_id
| 1 | teacher | 38 |
| 1 | teacher | 39 |
| 1 | teacher | 40 |
| 1 | teacher | 41 |
| 1 | teacher | 42 |
| 1 | teacher | 43 |
我使用 id 或 result 得到相同的结果,那么 resultMap 中的<result> 和<id> 标签有什么区别?
【问题讨论】:
标签: mybatis