1. 程式人生 > >MyBatis(九) 使用association定義單個對象的封裝規則

MyBatis(九) 使用association定義單個對象的封裝規則

myba last and emp name soci from prop mp3

(1)接口中編寫方法

public Emp getEmpandDept();

(2)編寫Mapper文件

 1   <resultMap type="com.eu.bean.Emp" id="emp3">
 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 <association property="dept" javaType="com.eu.bean.Dept"> 7 <id column="id" property="id"/> 8 <result column="dept_name" property="deptName"/> 9 </association> 10 </resultMap> 11   <select
id="getEmpandDept" resultMap="emp3"> 12    SELECT * 13 FROM emp e 14  JOIN dept d 15  ON e.d_id=d.id 16 </select>

MyBatis(九) 使用association定義單個對象的封裝規則