对于多个xml文件需要同时引用一段相同的 可以在某个xml 中定义这个 sql 代码片段,在需要引用的地方使用全称引用即可,例子如下:
ShareMapper.xml
<mapper namespace="com.company.ShareMapper">
<sql id="someSQL">
id,name
</sql>
</mapper>
CustomMapper.xml
<mapper namespace="com.company.CustomMapper">
<select id="selectSome" >
select
<include refid="com.company.ShareMapper.someSQL"/>
from t
</select>
</mapper>
本文介绍如何在一个项目中,通过在ShareMapper.xml中定义SQL片段,然后在CustomMapper.xml等其他mapper中引用,实现代码复用。适合理解和实践XML映射文件的高级用法。
7143

被折叠的 条评论
为什么被折叠?



