您现在的位置是:首页 > 文章详情

Mybatisplus-plus 1.5.0 发布,新增服务层根据复合主键批量更新操作

日期:2021-01-31点击:1140

需要在service使用多主键相关操作包括saveOrUpdateByMultiId和批量操作updateBatchByMultiId和saveOrUpdateBatchByMultiId,可以直接继承IMppService接口。

service层继承IMppService接口和MppServiceImpl

 public interface Test07Service extends IMppService<Test07Entity> { } public class Test07ServiceImpl extends MppServiceImpl<Test07Mapper, Test07Entity> implements Test07Service { }

在service层根据复合主键进行批量操作和saveOrUpdate操作

 @Test public void testSaveOrUpdateByMultiIdService(){ //id Test07Entity idEntity=new Test07Entity(); idEntity.setK1(6); idEntity.setK2("666"); //del test07Service.deleteByMultiId(idEntity); //add test07Service.saveOrUpdateByMultiId(idEntity); //update idEntity.setCol1("ccccc"); test07Service.saveOrUpdateByMultiId(idEntity); } @Test public void testSaveOrUpdateBatchByMultiIdService(){ //ids List<Test07Entity> entityList=new ArrayList<Test07Entity>(); for(int i=10;i<30;i++){ Test07Entity idEntity=new Test07Entity(); idEntity.setK1(i); idEntity.setK2(String.valueOf(i*10)); entityList.add(idEntity); } //del for(Test07Entity idEntity:entityList) { test07Service.deleteByMultiId(idEntity); } //add batch test07Service.saveOrUpdateBatchByMultiId(entityList); //del for(Test07Entity idEntity:entityList) { idEntity.setCol1(new Date().toString()); } //update batch test07Service.saveOrUpdateBatchByMultiId(entityList); } @Test public void testUpdateBatchByMultiIdService(){ //ids List<Test07Entity> entityList=new ArrayList<Test07Entity>(); for(int i=50;i<80;i++){ Test07Entity idEntity=new Test07Entity(); idEntity.setK1(i); idEntity.setK2(String.valueOf(i*10)); entityList.add(idEntity); } //del for(Test07Entity idEntity:entityList) { test07Service.deleteByMultiId(idEntity); } //add batch test07Service.saveOrUpdateBatchByMultiId(entityList); //del for(Test07Entity idEntity:entityList) { idEntity.setCol1(new Date().toString()); } //update batch test07Service.updateBatchByMultiId(entityList); }
原文链接:https://www.oschina.net/news/128464
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章