用foreach做批量更新的时候总是报错:
<update id="updateList" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
UPDATE T_JRAQ_PGJBXXSZ set
<if test="item.n_sfyx !=null">
N_SFYX=#{item.n_sfyx,jdbcType=DECIMAL}
</if>
WHERE
N_PGJBXXBID=#{item.n_pgjbxxbid,jdbcType=DECIMAL}
</foreach>
</update>
以下这种写法有效(经过测试):
<update id="updateList" parameterType="list">
update T_JRAQ_PGJBXXSZ
<trim prefix="set" suffixOverrides=",">
<trim prefix="N_SFYX =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.n_sfyx!=null">
when N_PGJBXXBID=#{i.n_pgjbxxbid} then #{i.n_sfyx}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or" item="i" index="index">
N_PGJBXXBID=#{i.n_pgjbxxbid}
</foreach>
</update>