sql.xml 循环插入与修改写法

时间:2023-03-10 00:27:19
sql.xml  循环插入与修改写法
 // 插入 (交互一次数据库)
<insert id="insertClient">
insert into m_linknodeclient (LinkClientID, LinkID,
UnitID, DevID, DevNodeID,
f_Param1, f_Param2, f_Param3,
ClientScreenID,
i_Flag, vc_Memo)
values
<foreach collection="clientList" item="list" separator=",">
(#{list.linkClientId,jdbcType=VARCHAR}, #{list.linkId,jdbcType=VARCHAR},
#{list.unitId,jdbcType=VARCHAR}, #{list.devId,jdbcType=VARCHAR}, #{list.devNodeId,jdbcType=VARCHAR},
#{list.fParam1,jdbcType=REAL}, #{list.fParam2,jdbcType=REAL}, #{list.fParam3,jdbcType=REAL},
#{list.clientScreenId,jdbcType=INTEGER},
#{list.iFlag,jdbcType=INTEGER}, #{list.vcMemo,jdbcType=VARCHAR})
</foreach>
</insert>
 // 修改  (交互多次数据库)
    <update id="updateClient" >
<foreach collection="clientList" item="list" index="index" open="" close="" separator=";">
update m_linknodeclient
<set>
<if test="list.linkId != null">
LinkID = #{list.linkId,jdbcType=VARCHAR},
</if>
<if test="list.unitId != null">
UnitID = #{list.unitId,jdbcType=VARCHAR},
</if>
<if test="list.devId != null">
DevID = #{list.devId,jdbcType=VARCHAR},
</if>
<if test="list.devNodeId != null">
DevNodeID = #{list.devNodeId,jdbcType=VARCHAR},
</if>
<if test="list.fParam1 != null">
f_Param1 = #{list.fParam1,jdbcType=REAL},
</if>
<if test="list.fParam2 != null">
f_Param2 = #{list.fParam2,jdbcType=REAL},
</if>
<if test="list.fParam3 != null">
f_Param3 = #{list.fParam3,jdbcType=REAL},
</if>
<if test="list.clientScreenId != null">
ClientScreenID = #{list.clientScreenId,jdbcType=INTEGER},
</if>
<if test="list.iFlag != null">
i_Flag = #{list.iFlag,jdbcType=INTEGER},
</if>
<if test="list.vcMemo != null">
vc_Memo = #{list.vcMemo,jdbcType=VARCHAR},
</if>
</set>
where LinkClientID = #{list.linkClientId,jdbcType=VARCHAR}
</foreach>
</update>