mybatis resultMap

https://mybatis.org/mybatis-3/zh/sqlmap-xml.html

A、实体类属性名称和数据库字段名不一致

结果映射

解决方案

1、sql语句字段起别名

select id, name as na from test

2、通过resultMap 结果集映射

接口类的配置文件

    <!--type 结果集映射 id 下面的 resultMap的映射 -->
    <resultMap id="userMap" type="User">
        <!--column 数据库中的字段 property 实体类中的属性-->
        <result column="pwd" property="password"/>
    </resultMap>
        <select id="getUserList" resultMap="userMap">
            select * from mybatis.user
        </select>

什么字段不一样,使用什么

                 

posted @ 2020-07-17 17:36  市丸银  阅读(126)  评论(0编辑  收藏  举报