MyBatis(10)使用association进行分步查询

时间:2023-03-09 03:14:21
MyBatis(10)使用association进行分步查询

(1)接口中编写方法

public Emp getEmpByStep(Integer id);
public Dept getDeptById(Integer id);

(2)Mapper文件

   <!-- 使用association进行分步查询 -->
<resultMap type="com.eu.bean.Emp" id="MyStep">
<id column="id" property="id"/>
<result column="last_name" property="lastName"/>
<result column="gender" property="geder"/>
<result column="email" property="email"/>
<association property="dept"
select="com.eu.dao.DeptDao.getDeptById"
column="d_id">
</association>
</resultMap>
 <select id="getEmpByStep" resultMap="MyStep">
select * from emp where id = #{id}
</select>