mybatis-plus 批量插入修改操作

77 阅读1分钟

mybaits-plus 的学习成本相对较低,当学会了mybatis之后,mybaits-plus 很有友好的对mybaits仅仅是增强,没有任何改变,学习难度较低;
其中有个小小的问题,即 IService中自带的 saveBatch 和 saveOrUpdateBatch 等方法,仔细看会发现,他们的批量执行,竟然不是 真正的批量执行!!!
IService 的实现类 ServiceImpl 中截取一段代码

/**
     * 批量插入
     *
     * @param entityList ignore
     * @param batchSize  ignore
     * @return ignore
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveBatch(Collection<T> entityList, int batchSize) {
        String sqlStatement = getSqlStatement(SqlMethod.INSERT_ONE);
        return executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
    }

会发现,其实是在循环插入, 那么如果这样我们有两种选择
1 使用mybatis 的xml

本文转自 jimolvxing.blog.csdn.net/article/det…,如有侵权,请联系删除。