方法1: 使用mybatis plus内置的方法。目前常用的就一下几个方法。 // 插入(批量)boolean saveBatch(Collection entityList);// 插入(批量)boolean saveBatch(Coll
方法1:
使用mybatis plus内置的方法。目前常用的就一下几个方法。
// 插入(批量)boolean saveBatch(Collection entityList);// 插入(批量)boolean saveBatch(Collection entityList, int batchSize);// 删除(根据ID 批量删除)boolean removeByIds(Collection extends Serializable> idList);
方法2:
使用xml编写sql文件进行批量查询。注意:foreach的使用
//批量添加//javapublic Integer batchAdd(List user)
insert into user(u_name,u_age) values(#{item.name},#{item.age})
注意:collection和item永远是必填项。
collection:
(1)只有一个参数的情况 List对象,则collection=“list”即可。
(2)只有一个参数的情况Array对象,则collection=“array” 即可。
(3)还有一种特殊情况。如下输入参数。如果想要遍历ids。那么此时指定collection=“ids”即可。
class User{private String name;private String[] ids;}
(4)多个参数,最好使用Param指定每个参数的别名。
让collection=“别名”(或者是map类型的输入参数,collection=“对应的key”)
来源地址:https://blog.csdn.net/qq_44895567/article/details/130622857
--结束END--
本文标题: mybatis plus-批量操作
本文链接: https://www.lsjlt.com/news/372093.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-08
2024-05-08
2024-05-08
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0