代码语言:javascript复制
@Resource
private SqlSessionFactory sqlSessionFactory;
@Override
public <T> void saveBatch(List<?> saveList, Class<? extends BaseMapper<T>> mappers) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
BaseMapper<T> mapper = sqlSession.getMapper(mappers);
for(int i = 0; i <= saveList.size() - 1; i ){
mapper.insert((T) saveList.get(i));
if(i % 1000 == 0){
sqlSession.commit();
sqlSession.clearCache();
}
}
sqlSession.commit();
sqlSession.clearCache();
}