1 @Transactional(rollbackFor = Exception.class)
 2 public void addUserOneByOne(List<User> users) {
 3     SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);
 4     UserMapper um = session.getMapper(UserMapper.class);
 5     long startTime = System.currentTimeMillis();
 6     for (User user : users) {
 7         um.addUserOneByOne(user);
 8     }
 9     session.commit();
10     long endTime = System.currentTimeMillis();
11     logger.info("一条条插入 SQL 耗费时间 {}", (endTime - startTime));
12 }

 

posted on 2021-11-25 15:47  kevenYuan  阅读(20)  评论(0编辑  收藏  举报