最重要的一点!
mybatis要想批量更新,首先我们数据库需要支持批量更新操作
需要在连接数据库时,添加配置
url: jdbc:mysql://192.168.6.11:3306/equipment_im_dev?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useUnicode=true&useSSL=false&allowMultiQueries=true
添加这个 才会支持 批量操作,要不然会报错
allowMultiQueries=true
首先展示一下我mapper层的代码
> void updateAllRepairedPosition(@Param("repairInfos") List<RepairInfo> repairInfos);
然后是xml文件中的代码
<update id="updateAllRepairedPosition">
<foreach collection="repairInfos" item="repairInfo" separator=";" index="index">
update repair_info
<set>
<if test="repairInfo.repairManName!=null and repairInfo.repairManName!=''">
repair_man_name=#{repairInfo.repairManName},
</if>
<if test="repairInfo.repairCosts!=null">
repair_costs=#{repairInfo.repairCosts},
</if>
<if test="repairInfo.fittings!=null and repairInfo.fittings!=''">
fittings=#{repairInfo.fittings},
</if>
<if test="repairInfo.picture!=null and repairInfo.picture!=''">
picture=#{repairInfo.picture},
</if>
<if test="repairInfo.remark!=null and repairInfo.remark!=''">
remark=#{repairInfo.remark},
</if>
</set>
<where>
id=#{repairInfo.id}
</where>
</foreach>
</update>