mybatis查询结果集的映射关系

文章讨论了在MyBatis中,使用resultType时需要确保数据库列名和实体类属性名一致,若启用驼峰规则则无需考虑;而使用resultMap则可以自由配置,不受驼峰规则影响,提供了更灵活的数据映射方式。
摘要由CSDN通过智能技术生成
  • 使用实体类当做resultType,如果mybatis没有开启驼峰规则,那么数据库的列名和实体类的属性名需要一模一样,实体类属性加@Column没有作用
<select id="selectM" parameterType="java.lang.String" resultType="com.leilankeji.cn.dao.User">
        select * from t_user where user_name =#{username}
    </select>

  • 使用resultMap当结果集,这样与驼峰规则就没有关系了,resultMap里怎么配,就怎么对应
<resultMap id="BaseResultMap" type="com.cn.dao.User">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="user_name" jdbcType="VARCHAR" property="userName" />
        <result column="password" jdbcType="VARCHAR" property="password" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="phone_number" jdbcType="CHAR" property="phoneNumber" />
        <result column="email" jdbcType="VARCHAR" property="email" />
        <result column="status" jdbcType="INTEGER" property="status" />
        <result column="role_id" jdbcType="INTEGER" property="roleId" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    </resultMap>
<select id="selectM" parameterType="java.lang.String" resultMap="BaseResultMap">
        select * from t_user where user_name =#{username}
    </select>

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值