查询的字段与resultType名称不一致解决方法

1 .为列名指定别名 别名和java实体类的属性名一致

select id,name,pwd as password from User where id = #{id}

2 .设置结果映射类型,就是resultmap

 <select id="selectUser" resultMap="UserMap">
        select id,name,pwd  from User where id = #{id}
    </select>
    <resultMap type="User" id="UserMap">
    <!-- id为主键 -->
        <id column="id"  property="id"></id>
        <!--column数据库中表的名  property是对应类的属性  -->
        <result column="name" property="name"></result>
        <result column="pwd" property="password"></result>
    </resultMap>


resultType和resultMap的区别

resultType:当使用resultType做SQL语句返回结果类型处理时,对于SQL语句查询出的字段在相应的pojo中必须有和它相同的字段对应,而resultType中的内容就是pojo在本项目中的位置。

resultMap:当使用resultMap做SQL语句返回结果类型处理时,通常需要在mapper.xml中定义resultMap进行pojo和相应表字段的对应。(多用于复杂的映射关系)

3.开启驼峰命名规则

下划线变成下一个字符的大小 last_name  lastName

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值