Mybatis resultMap的使用

153 阅读1分钟

解决JavaBean和数据库字段不一样的问题

如:

解决方式1

  • sql语句取别名(AS关键字)
<mapper namespace="com.mybatis.DAO.PeopleMapper">
    <select id="getPeopleList" resultType="P">
        select id AS idid, name, age, address from mybatis.people;
    </select>
</mapper>

解决方式2

  • 使用resultMap
<mapper namespace="com.mybatis.DAO.PeopleMapper">
    <resultMap id="PMap" type="P">
        
        <result column="id" property="idid"/>
        
    </resultMap>
    <select id="getPeopleList" resultMap="PMap">
        select id , name, age, address from mybatis.people;
    </select>
</mapper>