简体   繁体   中英

How to Reuse ResultMap in Mybatis in multiple Mapper.xml in association?

I have two tables , Patient and Report and I have created tow mappers pationt-mapper.xml and report-mapper.xml
in pationt-mapper.xml I have write this :

<resultMap type="Pationt" id="PationtResult">
        <id property="id" column="id"/>
        <result property="firstname" column="firstname"/>
        <result property="lastname" column="lastname"/>
        <result property="createdAt" column="created_at"/>
</resultMap>

in report-mapper.xml I have written this :

<resultMap type="Pationt" id="PationtResult">
        <id property="id" column="id"/>
        <result property="firstname" column="firstname"/>
        <result property="lastname" column="lastname"/>
        <result property="createdAt" column="created_at"/>
</resultMap>

<resultMap type="Report" id="ReportResult">
        <id property="id" column="id"/>
        <result property="reportText" column="report_text"/>
        <result property="lastname" column="lastname"/>
        <result property="createdAt" column="created_at" />
        <association property="pationt" resultMap="PationtResult" />
</resultMap>

I repeteed the resultmap over and over in multiple mappers files to use it in association.
How can I reuse resultmap to use it in another mapper file INTO association such as my code :

You can point to the other map using patientMapper.pationtResult in you resultMap Param.

For example: “ … “ *here patientMapper is the name space of the mapper you are referring

See below link for more info

Reusing MyBatis ResultMap in multiple mapper.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM