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


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.xxx.dao.mapper.TagMapper">
  <resultMap id="BaseResultMap" type="com.xxx.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.xxx.dao.TagExtendMapper">
    <select id="xxxxx" resultMap="com.xxx.dao.mapper.TagMapper.BaseResultMap"> <!-- 這里時原始命名空間加上結果集id -->
    </select>
</mapper>

  或者是

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

 

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM