1. 程式人生 > >Mybatis的XML映射文件的繼承問題

Mybatis的XML映射文件的繼承問題

resultmap batis pri 文件 clas ava database arch mybatis

1.首先dao層mapper.java需要繼承原來的接口

  原dao層接口

public interface TagMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table t_tag
     *
     * @mbg.generated
     */
    long countByExample(TagExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table t_tag
     *
     * @mbg.generated
     
*/ int deleteByExample(TagExample example); }

  擴展後的dao層接口

public interface TagExtendMapper extends TagMapper {
    ...
}

2.繼承原始mapper.xml的結果映射

  原始mapper.xml的結果映射

<mapper namespace="com.dreamcloudprint.dao.mapper.TagMapper">
  <resultMap id="BaseResultMap" type="com.dreamcloudprint.dao.Tag"
> <!-- WARNING - @mbg.generated This element is automatically generated by MyBatis Generator, do not modify. --> <id column="id" jdbcType="CHAR" property="id" /> <result column="tag_name" jdbcType="VARCHAR" property="tagName" /> <result column
="tag_alias" jdbcType="VARCHAR" property="tagAlias" /> </resultMap> </mapper>

  擴展mapper.xml的結果映射

<mapper namespace="com.dreamcloudprint.dao.TagExtendMapper">
    <select id="xxxxx" resultMap="com.dreamcloudprint.dao.mapper.TagMapper.BaseResultMap"> <!-- 這裏時原始命名空間加上結果集id -->
    </select>
</mapper>

  或者是

<mapper namespace="com.dreamcloudprint.dao.TagExtendMapper">
   <resultMap id="ExtBaseResultMap" type="com.dreamcloudprint.dao.Tag" extend="com.dreamcloudprint.dao.mapper.TagMapper.BaseResultMap">
       ...
  </resultMap>
</mapper>

個人筆記,價值不高,技術太菜,希望大家多多提意見,如果又什麽更好的技術歡迎分享哦!

Mybatis的XML映射文件的繼承問題