MyBatis查询:一对多映射关系


@Mapper
public interface ParameterMapper {
    Dept GetDeptAndEmp(@Param("id") Integer did);
}
<?xml version="1.0" encoding="UTF-8" ?>
DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mybatis_review.mapper.ParameterMapper">

    <resultMap id="GetDeptAndEmpMap" type="com.example.mybatis_review.bean.Dept">
        <id property="did" column="did">id>
        <result property="deptName" column="dept_name">result>
        <collection property="emps" ofType="com.example.mybatis_review.bean.Emp">
            <id property="eid" column="eid">id>
            <result property="did" column="did">result>
            <result property="empName" column="emp_name">result>
            <result property="email" column="email">result>
            <result property="did" column="did">result>
            <result property="age" column="age">result>
            <result property="sex" column="sex">result>
        collection>
    resultMap>

    <select id="GetDeptAndEmp" resultMap="GetDeptAndEmpMap">
        select * from t_dept left join t_emp on t_dept.did = t_emp.did where t_dept.did=#{id}
    select>
mapper>