MyBatis动态SQL的 sql片段
Sql中可将重复的sql提取出来,使用时用include引用即可,最终达到sql重用的目的。
把上面例子中的id, username, birthday, sex, address提取出来,作为sql片段,如下:
SELECT FROM `user`
AND sex = #{sex}
AND username LIKE
'%${username}%'
id, username, birthday, sex, address
如果要使用别的Mapper.xml配置的sql片段,可以在refid前面加上对应的Mapper.xml的namespace 例如下图