问题:
首先已经检查过代码并确认sql语法都对
<update id="batchUpdate">
<foreach collection="upList" item="d" separator=";">
update broadcast_status
<set>
<if test="d.deviceName != '' and d.deviceName != null">
device_name = #{d.deviceName},
</if>
<if test="d.deviceClass != '' and d.deviceClass != null">
device_class = #{d.deviceClass},
</if>
<if test="d.onlineStatus != '' and d.onlineStatus != null">
online_status = #{d.onlineStatus},
</if>
<if test="d.faultState != '' and d.faultState != null">
fault_state = #{d.faultState},
</if>
<if test="d.ocupyState != '' and d.ocupyState != null">
ocupy_state = #{d.ocupyState},
</if>
<if test="d.temp != '' and d.temp != null">
temp = #{d.temp},
</if>
<if test="d.modifyTime != null">
modify_time = #{d.modifyTime},
</if>
</set>
where bureau_code = #{bureauCode} and station_code = #{stationCode} and device_id = #{d.deviceId}
</foreach>
</update>
但是更新时还会报sql语法错误,更新不了。
原因:
mybatis默认不支持批量操作,需要在数据库连接配置文件的url中追加允许批量操作的属性:&allowMultiQueries=true
eg:
url: jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&allowMultiQueries=true
加上后就能正常批量插入了。
标签:code,批量,更新,device,出错,mybatis,true From: https://www.cnblogs.com/sensenh/p/17567380.html