计算机系统应用教程网站

网站首页 > 技术文章 正文

Mybatis的XML映射文件的继承问题 mybatis映射文件的主要元素及作用

btikc 2024-09-29 10:00:16 技术文章 18 ℃ 0 评论

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);
}

如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:854630135,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。

扩展后的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>

或者是

如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:854630135,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。

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

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表