Java 具有相同基本映射器的多个关联

Java 具有相同基本映射器的多个关联,java,mybatis,Java,Mybatis,我有一个版本信息的基本结果图,定义如下: <resultMap id="VersionedEntityMapper" type="org.chu.wit4h.db.AbstractVersionedEntity"> <result property="version" column="version"/> <result property="lastModified" column="lastModified"/> &

我有一个版本信息的基本结果图,定义如下:

   <resultMap id="VersionedEntityMapper" type="org.chu.wit4h.db.AbstractVersionedEntity">
      <result property="version" column="version"/>
      <result property="lastModified" column="lastModified"/>
      <result property="lastModifier" column="lastModifier"/>
   </resultMap>

然后是几个实体映射程序对其进行扩展:

   <resultMap id="Entity1Mapper" type="org.Entity1" extends="VersionedEntityMapper">
      <result property="name" column="name" />
      <result property="firstName" column="firstName" />
   </resultMap>

   <resultMap id="Entity2Mapper" type="org.Entity2" extends="VersionedEntityMapper">
      <result property="room" column="room"/>
   </resultMap>

在我这么做之前,一切都很顺利:

   <resultMap id="Entity3Mapper" type="org.Entity3">
      <id property="id" column="id" />
      <association property="info" javaType="org.Entity1" resultMap="Entity1Mapper"/>
      <association property="location" javaType="org.Entity2" resultMap="Entity2Mapper"/>
   </resultMap>

因此,列名version、lastModified和lastModifier冲突。
我可以在SQL语句中对它们进行别名,但如何将前缀传递给内部映射器?

为了使用现有的
resultMap
映射关联实体,您需要向结果中关联实体的所有列添加一些前缀,并通过
columnprofix
属性指定该前缀

在上面的示例中,
Entity1
的字段应命名为
Entity1\u name、Entity1\u first\u name、Entity1\u version
等。在选择
Entity3
的查询中

应修改映射:

<resultMap id="Entity3Mapper" type="org.Entity3">
   <id property="id" column="id" />
   <association property="info" javaType="org.Entity1" resultMap="Entity1Mapper"
       columnPrefix="entity1"/>
   ...
</resultMap>

...

您是否尝试在
关联
元素上使用
列前缀
属性?这对你不管用吗?如果没有,你会犯什么错误?不,我错过了那一个!事实上,它解决了上述问题。