// Mapper接口方法 int insertDepartment(String departmentName);
// XML配置
@Transactional
public void batchInsertUsers(List
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
try {
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
for (int i = 0; i < users.size(); i++) {
mapper.insertUser(users.get(i));
if (i % 1000 == 0) {
sqlSession.flushStatements();
}
}
sqlSession.commit();
} finally {
sqlSession.close();
}
}
你可能想看: