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

 

 个人笔记,价值不高,技术太菜,希望大家多多提意见,如果又什么更好的技术欢迎分享哦!

转载于:https://www.cnblogs.com/51ctoedu/p/9460617.html

你可能感兴趣的:(Mybatis的XML映射文件的继承问题)