Mybatis的批量操作,在Spring中使用Mybatis的批量处理

//使用批量插入的方法向数据库中插入100条记录
@Test
public void testbatchsave2() throws IOException{
	
	SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
	SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);
	try {
		Department department=new Department();
		department.setDepartmentId(1);
		for(int i=0;i<100;i++){
			Customer customer=new Customer("LL1", 1, "ll@", null);
			customer.setDepartment(department);
			CustomerMapper mapper = session.getMapper(CustomerMapper.class);
			mapper.saveCustomer(customer);				
		}
	} catch (Exception e) {
		e.printStackTrace();
	}finally {
		session.commit();	
		session.close();
	}
	
}`在这里插入代码片`

2.Spring中使用Mybatis的批量处理


		
				
	

你可能感兴趣的:(mybatis,Spring4)