resultMap 和 resultType

返回的结果集可以用resultType也可以用resultMap。

使用resultType:

<select id="getRole" parameterType="long" resultType="role">
        select id,role_name as roleName,note from t_role where id=#{id}
    </select>

使用resultMap:

<!--下面使用resultMap-->
    <resultMap id="roleResultMap" type="role">
        <id property="id" column="id"></id>
        <result property="roleName" column="role_name"></result>
        <result property="note" column="note"></result>
    </resultMap>
    <select id="getRole" parameterType="long" resultMap="roleResultMap">
        select id,role_name,note from t_role where id=#{id}
    </select>

其中,id是对应着的主键,而下面的result的属性是对应的pojo对象的属性。resultMap的type可以是完整的类名也可以是像role这样的别名(需要在MyBatis中配置).column是对应的数据库中的名称。这样就将数据库和pojo对象映射在一起了。

从上面的代码中可以看到二者的select语句的不同。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值