mybatis中数据库列名与实体对象属性名不一致解决办法

<!--解决数据库列名与实体对象属性名不一样的问题-->
    <!--1.修改sql语句,起别名。,这种方式最为高效,不浪费性能,但是麻烦-->
    <select id="findAll" resultType="com.domain.User">
        select id as userId,username as userName,address as userAddress,sex as userSex,birthday as userBirthday from user;
    </select>
    <!--2.配置xml文件,开发方便.注意!需要把resultType改成resultMap,resultMap的值就是上面resultMap的id值
    配置 查询结果的列名和实体类的属性名的对应关系-->
    <resultMap id="userMap" type="uSeR">
        <!--主键字段的对应:property实体对象属性名 column数据库列名-->
        <id property="userId" column="id"></id>
        <!--非主键字段的对应-->
        <result property="userName" column="username"></result>
        <result property="userAddress" column="address"></result>
        <result property="userSex" column="sex"></result>
        <result property="userBirthday" column="birthday"></result>
    </resultMap>-->
    <select id="findAll" resultMap="userMap">
        select * from user;
    </select>

 

转载于:https://my.oschina.net/u/3668429/blog/3046477

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值