mybatisPlus批量插入

news/2024/7/10 0:35:43 标签: java, mybatis, 接口, vue, 数据结构

mybatisplus批量插入">mybatisPlus批量插入

1、只有一个Service类没有impl的时候

  • 可以这么写
java">@Service
@Slf4j
public class OrgService extends ServiceImpl<OrgMapper,Org> implements IService<Org> {

    @Autowired
    private OrgMapper orgMapper;
    @Autowired
    private JxOrgService jxOrgService;


    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public boolean insertBatch(){
        ArrayList<Org> orgs = new ArrayList<>();
        //批量插入方法
        boolean b = saveBatch(orgs);
        //如果超过1000条了就多加个参数
        //saveBatch(orgs,2000);
        return b;
    }
}

//继承ServiceImpl<OrgMapper,Org> 第一个是service对应的mapper,第二个是实体类
//实现implements IService<Org> Org为实体类
  • 然后就可以调用savaBatch()方法了,默认只插入1000条,如果多就添加第二个方法参数

接口和serviceimpl实现类的时候">2、有Service接口和ServiceImpl实现类的时候

  • OrgService
java">public interface OrgService extends IService<Org> {

    public boolean insertBatch();
}
  • OrgServiceImpl
java">@Service
@Slf4j
public class OrgServiceImpl extends ServiceImpl<OrgMapper,Org> implements OrgService {

    @Autowired
    private OrgMapper orgMapper;
    @Autowired
    private JxOrgService jxOrgService;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public boolean insertBatch(){
        ArrayList<Org> orgs = new ArrayList<>();
        //批量插入方法
        boolean b = saveBatch(orgs);
        //如果超过1000条了就多加个参数
        //saveBatch(orgs,2000);
        return b;
    }

}

Q.E.D.


http://www.niftyadmin.cn/n/748144.html

相关文章

注重实效的程序员读书笔记

1发现他人的bug之后&#xff1a;要解决问题&#xff0c;而不是发出指责(Fix the Problem, Not the Blame)。 2在遇到bug之后要记住&#xff1a;不要恐慌(Dont Panic) 3编写羞怯的代码&#xff1a;不想别人暴露你自己&#xff0c;不与太多人打交道。 4要配置&#xff0c;不要集成…

SpringBoot+mybatisPlus实现多数据源

SpringBootmybatisPlus实现多数据源curd 适用场景&#xff1a;一个项目需要连接多个数据库的时候 dynamic-datasource-spring-boot-starter 是一个基于springboot的快速集成多数据源的启动器。 其支持 Jdk 1.7, SpringBoot 1.4.x 1.5.x 2.x.x。 示例项目 可参考项目下的samples…

c++写模板的注意事项

首先给出结论&#xff1a; c中和模板相关的代码&#xff0c;都放在.h文件当中。 为什么呢&#xff1f; 首先我们要理解编译器是怎么处理模板的&#xff1a;编译器在编译cpp或cc文件的时候&#xff0c;根据代码中使用到的参数类型&#xff0c;实例化对应版本的函数。 所以&a…

DataX-进阶版-性能调优及批量执行等

DataX-进阶版-性能调优及批量执行等 1、性能调优见链接 https://www.cnblogs.com/hit-zb/p/10940849.html 2、批量执行 先抽出数据库的配置参数为配置常量,用占位符代替 {"job": {"content": [{"reader": {"connection": [{"jdbc…

两台一级域名相同二级域名不同的服务器,怎么共享session

比如www.hongchangfirst.com和video.hongchangfirst.com两个域名&#xff0c;一级域名相同&#xff0c;二级域名不同。每个服务器运行着不同的功能模块或者不同的子系统&#xff0c;他们使用不同的二级域名&#xff0c;但用户系统是统一的&#xff0c;即一套用户名、密码在整个…

bat批处理文件语句及用法记录

bat批处理文件语句及用法记录 参考链接 https://www.cnblogs.com/liangblog/p/9835940.html 1、批量输出文件名 for %%i in (*.json) do (echo %%~nxi ) echo off setlocal enabledelayedexpansionset signc:\users\suxq\desktop\sign.jar set apkPathc:\users\suxq\desktop\ou…