<sql>
element like this:
<sql id="update_fragment">
<set>
<if test="id != null">
id = #{id},
</if>
<if test="name != null">
id = #{name},
</if>
...
</set>
</sql>
And it's used in a <update>
:
<update id="update" parameterType="MyTableBean">
UPDATE MyTable
<include refid="update_fragment"/>
WHERE id =# {id}
</update>
In DAO:
Integer update(MyTableBean myTableBean);
Now, I write a batchUpdate method:
Integer batchUpdate(@Param("ids")List<Integer> ids, @Param("bean")MyTableBean myTableBean);
And I want to re-use the 'update_fragment' <sql>
element.
<update id="update">
UPDATE MyTable
<include refid="update_fragment"/>
WHERE ids IN
<foreach>...</foreach>
</update>
But it seems the scope in 'update_fragment' is wrong.
It seems that I have to rewrite a <sql>
which changes #{id}
to #{bean.id}
.
It's there any way to re-use the statement without rewrite a new <sql>
.