mybatis xml 文件中对于重复出现的sql 片段可以使用标签提取出来,在使用的地方使用标签引用即可具体用法如下:
<sqlid="someSQL">
id,name
</sql><selectid="selectSome" >
select
<includerefid="someSQL"/>
from t
</select>
1
2
3
4
5
6
7
8
在中可以使用${}传入参数,如下:
<sqlid="someSQL">
${tableName}.id,${tableName}.name
</sql><selectid="selectSome" >
select
<includerefid="someSQL"><propertyname="tableName"value="t"/></include>
from t
</select>