Mybatisの一括操作は、SpringでMybatisの一括処理を使用します.

993 ワード

//                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を使用した一括処理