@Autowired
private SqlSessionFactory sqlSessionFactory;
//
// @Resource
// private RoleEntityMapper roleEntityMapper;
public int testBatchExecutorInsert(ArrayList<RoleEntityWithBLOBs> objects) {
RoleEntityMapper roleEntityMapper;
SqlSession sqlSession = null;
int i = 0;
try {
sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
// SqlSession session = ssf.openSession(ExecutorType.BATCH);
// session = ssf.openSession();
roleEntityMapper = sqlSession.getMapper(RoleEntityMapper.class);
for (RoleEntityWithBLOBs role :objects){
i += roleEntityMapper.insertMulti(role);
}
sqlSession.commit();
}catch (Exception e){
log.error("批量插入更新异常",e);
if (sqlSession != null) {
sqlSession.rollback();
}
}finally {
if (null != sqlSession) {
sqlSession.close();
}
}
return i;
}
mybatis batchExecutor
最新推荐文章于 2024-07-07 14:30:38 发布
关键词由CSDN通过智能技术生成