resultMap和resultType的区别

本文详细介绍了MyBatis中resultType和resultMap的使用方法。resultType用于简单映射,当数据库列名与Java对象属性一致时直接映射。而resultMap则允许自定义映射规则,即使列名与属性名不一致也能处理。通过示例展示了如何配置和使用这两个特性,强调了resultMap的灵活性和自定义性。
摘要由CSDN通过智能技术生成

1、resultType的使用

<select id="findUserById" parameterType="int" resultType="com.bbz.pojo.UserInfo">
  select * from userInfo  where id = #{id}
</select>

2、resultMap的使用

<resultMap id="userResultMap" type="User">
  <id property="id" column="id" />
  <result property="username" column="username"/>
  <result property="password" column="password"/>
</resultMap>

 

<select id="findUserById" parameterType="int" resultMap="userResultMap">
  select * from  userInfo  where id = #{id}
</select>

3、总结

相同点:
(1)resultType和resultMap都是标识sql语句的返回值类型
不同点:
(1)resultMap需要自己先定义,使用resultType的时候,要保证结果集的列名与java对象的属性相同,而resultMap则不用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值