mybatis批量操作

批量操作

1、sql语句里foreach循环拼接

2、foreach循环里拼接sql, 以;分割

3、利用mybatis批处理,批量提交

     //添加
        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
        QuartzTaskMapper mapper = sqlSession.getMapper(QuartzTaskMapper.class);
        try {
            statisticsList.forEach(statistics -> mapper.updateStatistics(statistics));
            sqlSession.commit();
        } catch (Exception e) {
            sqlSession.rollback();
            e.printStackTrace();
        } finally {
            sqlSession.close();
        }

 

posted @ 2021-11-09 17:22  wujingqi  阅读(127)  评论(0编辑  收藏  举报