其他分享
首页 > 其他分享> > 11、mybatis学习——自定义结果映射resultMap

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接口定义方法

 

   测试方法

 

标签:11,mapper,级联,自定义,resultMap,sqlmapper,接口定义,id,测试方法
来源: https://www.cnblogs.com/lyh233/p/12347818.html