(1)接口中编写方法
1 public Emp getEmpandDept();
(2)编写Mapper文件
1 <resultMap type="com.eu.bean.Emp" id="emp2"> 2 <id column="id" property="id"/> 3 <result column="last_name" property="lastName"/> 4 <result column="gender" property="geder"/> 5 <result column="email" property="email"/> 6 <result column="id" property="dept.id"/> 7 <result column="dept_name" property="dept.deptName"/> 8 </resultMap> 9 10 <select id="getEmpandDept" resultMap="emp2"> 11 SELECT * 12 FROM emp e 13 JOIN dept d 14 ON e.d_id=d.id 15 </select>
本文详述了使用MyBatis进行复杂关联查询的方法,包括接口定义、Mapper文件配置及SQL语句编写,实现员工及其部门信息的一次性加载。
270

被折叠的 条评论
为什么被折叠?



