对于多个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>