Reputation: 25
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 :
Upvotes: 1
Views: 1527
Reputation: 76
You can point to the other map using patientMapper.pationtResult in you resultMap Param.
For example:
<select id=“getPatientReports” resultMap=“patientMapper.patientResult”>
…your query here
</select>
*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
Upvotes: 1