mybatis-03-增删改查

文章介绍了MyBatis框架中处理结果集的方式,包括resultMap的显式定义,用于自定义字段映射,提高查询效率;resultType用于简单的类型转换;类型别名简化全限定类名的使用;以及自动将下划线命名转换为驼峰命名的配置选项。
摘要由CSDN通过智能技术生成

传入参数类型parameterType

不需要写,有自动的类型转换处理器

返回参数类型resultType,resultMap

resultType值为返回类型的全限定名或者别名

resultMap显示自定义结果映射

//设置resultMap。指定唯一的id结果集,能让速度更快
<resultMap id="userResultMap" type="User">
  <id property="id" column="user_id" />
  <result property="username" column="user_name"/>
  <result property="password" column="hashed_password"/>
</resultMap>
//使用resultMap
<select id="selectUsers" resultMap="userResultMap">
  select user_id, user_name, hashed_password
  from some_table
  where id = #{id}
</select>

resultMap隐式结果映射:在sql中设置结果映射

<select id="selectUsers" resultType="User">
  select
    user_id             as "id",
    user_name           as "userName",
    hashed_password     as "hashedPassword"
  from some_table
  where id = #{id}
</select>

类型别名

<!-- mybatis-config.xml 中 -->
<typeAlias type="com.someapp.model.User" alias="User"/>

自动结果映射

mapUnderscoreToCamelCase=true
下划线命名自动转驼峰命名
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值