Reusing MyBatis ResultMap in multiple mapper.xml

亡梦爱人 提交于 2019-11-29 01:24:44

Once you import all the mapper xmls in mybatis-config.xml file you can refer ResultMaps configured in any of the mapper xmls using resultMap id along with namespace.

for Ex: ProjectMapper.xml

<mapper namespace="com.mybatisapp.mappers.ProjectMapper">
    <resultMap id="ProjectMap" type="com.model.Project">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="name" jdbcType="VARCHAR" property="name" />     
    <resultMap>
</mapper>

In ClientWithProjectsMapper.xml

    <select id="selectProjectsByClient" parameterType="int" 
resultMap="com.mybatisapp.mappers.ProjectMapper.ProjectMap">
    select * from blahblah
    </select>

Here you can reference resultMap in another Mapper xml files using fully qualified name as "com.mybatisapp.mappers.ProjectMapper.ProjectMap"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!