IBATIS如何复用SQL片段

为了消除重复片段,我们使用【sql】和【include】标签。【sql】标签用来包含重复片段,【include】标签用来引入片段: xml 代码

<sql id="selectItem_fragment">
FROM items
WHERE parentid = 6
sql>
<select id="selectItemCount" resultClass="int">
SELECT COUNT(*) AS total
<include refid="selectItem_fragment"/>
select>
<select id="selectItems" resultClass="Item">
SELECT id, name
<include refid="selectItem_fragment"/>
select>

猜你喜欢

转载自tanglichun.iteye.com/blog/1488527