MyBatisPlus批量操作
0
处理默认的saveBatch和updateBatch意外可以自己实现一些批量操作,继承ServiceImpl:
@Override
public void batch(List<Entity> list) {
this.executeBatch(list, (sqlSession, entity) -> sqlSession.insert("insertBatch", entity));
}
<insert id="insertBatch">
insert into t_entity(id) values (#{id})
</insert>
如果提示SqlSession Transaction not enabled
,有可能是我们内部方法没有代理,需要添加@Transactional(rollbackFor = Exception.class)
,或者使用代理执行方法AopContext.currentProxy()
。
推荐使用代理调用,因为有时候使用事务事务量太大容易导致系统崩溃。