MyBatis的批量操作

在sqlSessionFactory创建sqlSession是传入参数ExecutorType.BANTCH,以实现批量操作的sqlSession对象。

        //可以执行批量操作的sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)

 

    @Test
    public void testBatch() throws IOException {
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();

        //可以执行批量操作的sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);

        EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class);

        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            mapper.addEmp(new Employee(null, UUID.randomUUID().toString().substring(0,5),UUID.randomUUID().toString().substring(0,5)+"@qq.com","0"));
        }
        sqlSession.commit();
        long end = System.currentTimeMillis();

        System.out.println("执行时长"+(end-start));//14905===20582
    }

 

上一篇:mybatis 读取配置文件,得到SqlSessionFactory实例.


下一篇:windows环境下yolov5导出engine文件用于tensorrt部署