MyBatis(10)使用association进行分步查询
(1)接口中编写方法
public Emp getEmpByStep(Integer id);
public Dept getDeptById(Integer id);
(2)Mapper文件
1 <!-- 使用association进行分步查询 --> 2 <resultMap type="com.eu.bean.Emp" id="MyStep"> 3 <id column="id" property="id"/> 4 <result column="last_name" property="lastName"/> 5 <result column="gender" property="geder"/> 6 <result column="email" property="email"/> 7 <association property="dept" 8 select="com.eu.dao.DeptDao.getDeptById" 9 column="d_id"> 10 </association> 11 </resultMap> 12 <select id="getEmpByStep" resultMap="MyStep"> 13 select * from emp where id = #{id} 14 </select>