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>
个人笔记,价值不高,技术太菜,希望大家多多提意见,如果又什么更好的技术欢迎分享哦!
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步