<?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.lc.mybatis.mapper.DeptMapper">

    <!-- 部门查询  resultMap -->
    <resultMap id="deptResultMap" type="com.lc.mybatis.entity.Dept"  >
        <!-- 部门属性 省略 -->
        <result column="id" property="id"/>
        <result column="dname" property="dname"/>
        <result column="ddesc" property="ddesc"/>
        <!--
            collection 一对多映射
            用户属性 ofType 全路径名称  userList的 类型-->
        <collection property="userList" ofType="com.lc.mybatis.entity.User"   >
            <id column="uid" property="id"/>
            <result column="username" property="username"/>
            <result column="password" property="password"/>
            <result column="gender" property="gender"/>
        </collection>
    </resultMap>

    <!-- 部门查询 -->
    <select id="getDeptById" resultMap="deptResultMap" >
        SELECT
            d.* ,
            u.id uid,
            u.username username,
            u.password password,
            u.gender gender
        FROM
            t_dept d
                LEFT JOIN  t_user u ON d.id = u.d_id
        WHERE
            d.id = #{id}
    </select>

    <!-- getDeptByIdStep -->
    <select id="getDeptByIdStep" resultType="com.lc.mybatis.entity.Dept">
        SELECT * FROM t_dept WHERE id = #{id}
    </select>

</mapper>