后端框架学习-----mybatis(4)

4、解决属性名和字段名不一致的问题

1、问题。数据库字段名和属性名不一致,导致查出的数据部分为空
2、resultMap(用于解决数据库表中的字段和属性)

    
    <!--结果集映射-->
    <resultMap id="" type="">
        <!--column数据库中的字段,property实体类中的属性-->
        <result column="id" property="id"></result>
        <result column="name" property="name"></result>
        <result column="pwd" property="password"></result>
    </resultMap>
    
    <select id="selectUserById" resultMap="UserMap">
        select * from mybatis.user where id=#{id}

    </select>
  • resultMap元素是mybatis中最重要最强大的元素
  • ResultMap的设计思想是,对于简单的语句根本不需要配置显示的结果集,而对于复杂一点的语句只需要描述他们的关系就好
  • resultMap最优秀的地方在于,虽然对他们相当了解,但是不需要显示的用到他们
posted on 2022-08-28 22:19  热爱技术的小郑  阅读(12)  评论(0编辑  收藏  举报