resultMap属性使用场景:
表中字段名称与对象当中属性名不一致
关联查询时,实现数据的封装
1.左连接查询
collection集合标签 property表示实体类中的属性 ofType表示实体类中属性对应的集合当中泛型中的对象类型
<select id="findAll" resultMap="deptRM">
select
e.emp_id,
e.emp_name,
d.dept_id,
d.dept_name
from
emp e left join dept d
on
e.dept_id=d.dept_id
</select>
<resultMap id="deptRM" type="Dept">
<id column="dept_id" property="deptId"/>
<result column="dept_name" property="deptName"/>
<collection property="emps" ofType="Emp">
<id property="empId" column="emp_id"/>
<result column="emp_name" property="empName"/>
</collection>
</resultMap>
2.子查询 column 将查询到的字段值作为参数传递给子查询
select 属性 子查询的sql中id属性的值
<select id="selectChildren" resultMap="deptRMs"> select * from dept </select> <resultMap id="deptRMs