<resultMap>标签下的子标签
<association>处理单个对象数据
<collection>处理多个对象
1. 一对一
Student类
public class Student {
private Integer id;
private String name;
private Integer age;
// 一对一
private Computer computer;
//...省略
}
Computer类
public class Computer {
private Integer id;
private String moudle;
}
数据库里学生和电脑信息在两张表里存储
要求查出学生时,把电脑信息也查出来
<select id="selAll" resultMap="StudentResultMap">
select s.`s_id`,s.`s_name`,s.`s_age`,s.`c_id`,c.`c_moudle`
from student s inner join computer c where s.`c_id`=c.`c_id`
</select>
<!--一对一-->
<resultMap id="StudentResultMap" type="Student">
<id column="s_id" property="id"></id>
<result column="s_name" property="name"></result>
<result column="s_age" property="age"></result>
<association property="computer" javaType="Computer">
<id column="c_id" property="id"></id>
<result column="c_moudle" property