目录
- myBATis批量更新list对象
- 最重要的一点
- 展示一下我mapper层的代码
- 总结
mybatis批量更新list对象
最重要的一点
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> repairInfojss);
然后是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.repairMa编程nName},
编程客栈 </if>
<if test="repairInfo.repairCosts!=null">
repair_costs=#php{repairInfo.repairCosts},
</if>
<if test="repairInfo.fittings!=nullphp 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>

总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。
加载中,请稍侯......
精彩评论