for循环插入数据

image.png

Batch插入 rewriteBatchedStatements=true

MapperBatchAction<BugMapper> action = MapperBatchAction.create(BugMapper.class, sqlSessionFactory);
        for (Bug bug : list) {
            action.addAction(mapper->mapper.insertSelective(bug));
        }
        return action.doBatchActions();

image.png

Batch插入 rewriteBatchedStatements=false

MapperBatchAction<BugMapper> action = MapperBatchAction.create(BugMapper.class, sqlSessionFactory);
        for (Bug bug : list) {
            action.addAction(mapper->mapper.insertSelective(bug));
        }
        return action.doBatchActions();

image.png

Batch修改 rewriteBatchedStatements=true

public int update2000(List<Bug> list){
        MapperBatchAction<BugMapper> action = MapperBatchAction.create(BugMapper.class, sqlSessionFactory);
        for (Bug bug : list) {
            action.addAction(mapper->mapper.updateByPrimaryKeySelective(bug));
        }
        return action.doBatchActions();
    }

image.png

Batch修改 rewriteBatchedStatements=false

public int update2000(List<Bug> list){
        MapperBatchAction<BugMapper> action = MapperBatchAction.create(BugMapper.class, sqlSessionFactory);
        for (Bug bug : list) {
            action.addAction(mapper->mapper.updateByPrimaryKeySelective(bug));
        }
        return action.doBatchActions();
    }

image.png

image.png

show variables like 'general_log%' ;
set global general_log='ON' ;


# general_log_file 可查看sql最终执行的语句