11、mybatis学习——自定义结果映射resultMap

一、没有级联属性的情况时

  

   sqlmapper文件配置

    <!-- 自定义resultMap
            type:指定返回的类型;id:指定resultMap的唯一标识 -->
    <resultMap type="com.pxxy.bean.Employee" id="empMap">
        <id column="id" property="id"/>
        <!-- 列名和属性名一样的时候可以不写 -->
        <result column="name" property="name"/>
        <result column="gender" property="gender"/>
    </resultMap>
        
        <!-- 返回resultMap -->
    <select id="selectEmpById" resultMap="empMap">
        select * from employee where id = #{emp_id}
    </select>

  mapper接口定义方法

   测试方法:

二、有级联属性的情况时

    student关联college

 

    sqlmapper文件配置

   mapper接口定义方法

   测试方法

猜你喜欢

转载自www.cnblogs.com/lyh233/p/12347818.html