1.修改Dept实体类:
一对多sql语句:
select d.id,d.name,e.salary,e.name,e.birthday
from dept d
left JOIN employee e on d.id=e.dept
2.编写配置文件
<resultMap id="deptEmpMap" type="Dept">
<id property="id" column="id"/>
<result property="name" column="name"/>
<collection property="emps" ofType="Employee">
<id column="eid" property="id" />
<result column="salary" property="salary"/>
<result column="ename" property="name"/>
</collection>
</resultMap>
<select id="getDeptWithEmp" resultMap="deptEmpMap">
select d.id,d.name,e.id eid,e.salary,e.name ename,e.birthday,e.dept
from dept d
left JOIN employee e on d.id=e.dept
</select>
测试: