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

栏目: 软件资讯 · 发布时间: 3年前

内容简介:需要在service使用多主键相关操作包括saveOrUpdateByMultiId和批量操作updateBatchByMultiId和saveOrUpdateBatchByMultiId,可以直接继承IMppService接口。 service层继承IMppService接口和MppServiceImpl publ...

需要在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);

    }

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

从零开始学架构

从零开始学架构

李运华 / 电子工业出版社 / 2018-9-21 / 99

本书的内容主要包含以下几部分:1) 架构设计基础,包括架构设计相关概念、历史、原则、基本方法,让架构设计不再神秘;2) 架构设计流程,通过一个虚拟的案例,描述了一个通用的架构设计流程,让架构设计不再依赖天才的创作,而是有章可循;3) 架构设计专题:包括高性能架构设计、高可用架构设计、可扩展架构设计,这些模式可以直接参考和应用;4) 架构设计实战,包括重构、开源方案引入、架构发展路径、互联网架构模板......一起来看看 《从零开始学架构》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具