resultMap2_关联查询2_association定义关联对象封装规

EmployeeMapperPlus.xml代码对比

  ①方法一:

<resultMap type="com.atguigu.mybatis.bean.Employee" id="MyDifEmp">
        <id column="id" property="id"/>
        <result column="email" property="email"/>
        <result column="last_name" property="lastName"/>
        <result column="gender" property="gender"/>
        <result column="did" property="dept.id"/>
        <result column="dept_name" property="dept.departmentName"/>
    </resultMap>

   ②方法二:

<resultMap type="com.atguigu.mybatis.bean.Employee" id="MyDifEmp2">
        <id column="id" property="id"/>
        <result column="email" property="email"/>
        <result column="last_name" property="lastName"/>
        <result column="gender" property="gender"/>
        <!-- 
            association可以指定联合的JavaBean对象
            property=“dept”:指定哪个属性是联合的对象
            JavaType:指定这个属性的类型
         -->
        <association property="dept" javaType="com.atguigu.mybatis.bean.Department">
            <id column="did" property="id"/>
            <result column="dept_name" property="departmentName"/>
        </association>
        
    </resultMap>

 注:association可以指定联合的JavaBean对象

   property=“dept”:指定哪个属性是联合的对象

   JavaType:指定这个属性的类型

posted @ 2018-01-09 03:05  2016024291-董诗原  阅读(184)  评论(0编辑  收藏  举报