原创

mybatis动态sql

<!--批量动态更新,只产生一条sql,-->
<update id="batchUpdateDeviceVoiceByCallback">
UPDATE pro_device_voice SET voice_status=
<foreach collection="list" item="item" index="index" separator=" " open="case device_imei" close="end">
when #{item.deviceImei} then #{item.voiceStatus}
</foreach>
WHERE batch_no = #{dto.batchNo}
AND device_imei IN
<foreach collection="dto.list" index="index" item="item" separator="," open="(" close=")">
#{item.deviceImei,jdbcType=BIGINT}
</foreach>
</update>
<!--批量更新,需要在连接建立的时候允许批量更新-->
<!--jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true-->
<insert id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
UPDATE pro_device
SET
is_deleted = #{item.deleteSign},
modify_time = NOW(),
modify_id = #{item.userId,jdbcType=BIGINT}
WHERE device_id = #{item.deviceId}
</foreach>
</insert>
<!--批量新增1.多条sql 支持事务-->
<insert id="insertList" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
INSERT INTO t_account_list
(account_submitor,account_gender,accoun)
VALUES
(#{item.accountSubmitor},#{item.accountGender})
</foreach>
</insert>
<!--批量更新,只会产生一条sql-->
<insert id="batchInsertDeviceVoice">
INSERT INTO pro_device_voice
(send_user_id, send_user_name)
VALUES
<foreach collection="list" item="deviceVoice" separator=",">
(#{deviceVoice.sendUserId,jdbcType=BIGINT}, #{deviceVoice.sendUserName,jdbcType=VARCHAR})
</foreach>
</insert>
正文到此结束

相关文章

Loading...