其他分享
首页 > 其他分享> > MyBatis查询:一对多映射关系

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>
<!--    Emp GetDeptAndEmp(@Param("id") Integer did);-->
    <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>

 

标签:Mapper,join,映射,did,查询,dept,emp,MyBatis,id
来源: https://www.cnblogs.com/zhyjdjm/p/16364947.html