1、首先定义一个sql标签,一定要定义唯一id<sql id="Base_Column_List" >name,age</sql>
2、然后通过id引用
<select id="selectAll">
select
<include refid="Base_Column_List" />
from student
</select>
这个<include refid="Base_Column_List" />会自动把上面的代码贴过来
2、然后通过id引用
<select id="selectAll">
select
<include refid="Base_Column_List" />
from student
</select>
这个<include refid="Base_Column_List" />会自动把上面的代码贴过来

本文介绍了一种在MyBatis中实现SQL代码复用的方法:通过定义带有唯一ID的SQL片段,并利用<include refid>标签进行引用。这种方法能够减少重复代码,提高开发效率。
2035

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



