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>

 

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

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值