目地:提高sql的复用性 ,将重复的SQL语句抽取出来,放到<sql>标签中,可以进行复用。
<!-- 定义sql片段 -->
<sql id="selectUser">
select * from User
</sql>
<!-- 查询某个商品的详细信息 -->
<select id="loadUserById" parameterType="java.lang.Integer"
resultType="com.bjsxt.pojo.User">
<!-- select * from user where uid=${value} -->
<!-- 引用sql片段 -->
<include refid="selectUser"></include>
where pid=${value}
</select>
注意:最好不要太复杂的语句
不要将<where>和<set>标签放到SQL片段中。