<mapper namespace="com.alex.myBatis2.dao.DeptDao">
<resultMap id="MyDept" type="Dept">
<id column="deptId" property="deptId"/>
<result column="deptName" property="deptName"/>
<result column="enable" property="enable"/>
<result column="pid" property="pid"/>
<collection property="emps" ofType="Emp">
<id column="empid" property="id"/>
<result column="age" property="age"/>
<result column="create_time" property="createTime"/>
<result column="name" property="name"/>
</collection>
</resultMap>
<sql id="select">select * from dept</sql>
<select id="selectAll" resultMap="MyDept">
SELECT emp.empid,emp.age,emp.create_time,emp.`name`,dept.deptName,dept.pid,dept.`enable`,dept.deptId FROM emp INNER JOIN dept ON dept.deptId=emp.deptId where dept.deptId=1;
</select>
<select id="list" resultType="dept" parameterType="dept">
<include refid="select"/>
<where>
<if test="deptName!=null and deptName!=''">
and deptName =#{deptName}
</if>
<if test="enable==1">
and enable=#{enable}
</if>
</where>
</select>
<select id="findByPid" parameterType="dept" resultType="dept">
<include refid="select"/>
<where>
<choose>
<when test="pid==1">
pid=1</when>
<otherwise>pid=4 and enable=1
</otherwise>
</choose>
</where>
</select>
<select id="findByid" resultType="com.alex.myBatis2.entity.Dept">
<include refid="select"/> where deptId in <foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="find" resultType="com.alex.myBatis2.entity.Dept">
SELECT deptId,deptName from dept
</select>
</mapper>
<resultMap id="myResult" type="Emp">
<id column="empid" property="id"/>
<result column="age" property="age"/>
<result column="create_time" property="createTime"/>
<result column="name" property="name"/>
<association property="dept" javaType="Dept">
<id column="deptId" property="deptId"/>
<result column="deptName" property="deptName"/>
<result column="enable" property="enable"/>
<result column="pid" property="pid"/>
</association>
</resultMap>