【串线篇】SQL映射文件-resultMap自定义封装

mybatis默认封装规则:

1)、按照列明和属性名一一对应的规则(不区分大小写)

2)、如果不一一对应:

              1)、开启驼峰命名(数据库aaa_bbb, 程序中aaaBbb)

              2)、起别名

              3)、自定义结果集(resultMap):自己定义每一列数据和javaBean(当乱起名时)的映射规则

              将resultType改为自己定义的resultMap去引用自己定义的

<select id="getCatById" resultMap="mycat">

        select *  from t_cat where id=#{id}

</select>
 

<resultMap type="com.atguigu.bean.Cat" id="mycat">

        <!-- 指定主键列的对应规则;

        column="id":指定哪一列是主键列

        property="":指定Cat的哪个属性封装id这一列数据

         -->

        <id property="id" column="id"/>

        <!-- 普通列 -->

        <result property="name" column="cName"/>

        <result property="age" column="cAge"/>

        <result property="gender" column="cgender"/>

</resultMap>
原文地址:https://www.cnblogs.com/yanl55555/p/11936249.html