第一步:
第二步:
第二种方法:
<!-- 自定义结果集,使用级联属性封装第2种方式-->
<resultMap id="myMapJiLian" type="com.yunqing.mybatis.bean.User">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="age" property="age"/>
<result column="did" property="dep.id"/>
<result column="dep_name" property="dep.departmentName"/>
</resultMap>
<!--使用级联属性-->
<select id="getUserAndDepById" resultMap="myMapJiLian">
SELECT u.id id,u.name name,u.age age,u.dep_id dep_id,dep.id did,dep.department dep_name FROM t_user u,t_dep dep WHERE
u.dep_id=dep.id AND u.id=#{id}
</select>