MyBatis(九) 使用association定义单个对象的封装规则

(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>

猜你喜欢

转载自www.cnblogs.com/wanerhu/p/10720887.html