【问题标题】:How to Reuse ResultMap in Mybatis in multiple Mapper.xml in association?如何在关联的多个Mapper.xml中复用Mybatis中的ResultMap?
【发布时间】:2021-11-02 12:09:07
【问题描述】:

我有两个表,Patient 和 Report,我创建了两个映射器,patient-mapper.xml 和 report-mapper.xml
在 patient-mapper.xml 我写了这个:

<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>

在 report-mapper.xml 我写了这个:

<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>

我在多个映射器文件中一遍又一遍地重复结果图,以便在关联中使用它。
如何重用 resultmap 以在另一个映射器文件 INTO 关联中使用它,例如我的代码:

【问题讨论】:

    标签: java mybatis


    【解决方案1】:

    您可以在 resultMap 参数中使用 patientMapper.pationtResult 指向另一张地图。

    例如:

    <select id=“getPatientReports”  resultMap=“patientMapper.patientResult”>
    …your query here
    </select>
    

    *这里的patientMapper是你所指的mapper的命名空间

    查看以下链接了解更多信息

    Reusing MyBatis ResultMap in multiple mapper.xml

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 2019-11-20
      • 1970-01-01
      • 2017-02-26
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多