网络维护员,seo关键词排名优化官网,直播软件开发一个多少钱,机票小代理做网站注#xff1a;Mybatis实现批量更新有三种方式#xff0c;分别是使用foreach标签、使用SQL的case when语句和使用动态SQL的choose语句。具体实现方法如下#xff1a;
1#xff1a;使用foreach标签
update idbatchUpdate parameterTypejava.util.Lis…注Mybatis实现批量更新有三种方式分别是使用foreach标签、使用SQL的case when语句和使用动态SQL的choose语句。具体实现方法如下
1使用foreach标签
update idbatchUpdate parameterTypejava.util.Listupdate user set name#{name}, age#{age} where id#{id}foreach collectionlist itemitem indexindex separator;update user set name#{item.name}, age#{item.age} where id#{item.id}/foreach
/update
2使用SQL的case when语句
update idbatchUpdate parameterTypejava.util.Listupdate user set name case idforeach collectionlist itemitem indexindex separator when #{item.id} then #{item.name}/foreachend,age case idforeach collectionlist itemitem indexindex separator when #{item.id} then #{item.age}/foreachendwhere id inforeach collectionlist itemitem indexindex open( close) separator,#{item.id}/foreach
/update
3使用动态SQL的choose语句
update idbatchUpdate parameterTypejava.util.Listforeach collectionlist itemitem indexindex separator;choosewhen testitem.name ! null and item.age ! nullupdate user set name#{item.name}, age#{item.age} where id#{item.id}/whenwhen testitem.name ! nullupdate user set name#{item.name} where id#{item.id}/whenwhen testitem.age ! nullupdate user set age#{item.age} where id#{item.id}/when/choose/foreach
/update