public void addEmps(@Param("emps")List emps);
2映射文件配置
insert into tbl_employee(last_name,email,gender,did)
values
(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})
3进行测试
@Test
public void testBatchSave() throws IOException{
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession openSession = sqlSessionFactory.openSession();
try{
EmployeeMapperDynamicSQL mapper = openSession.getMapper(EmployeeMapperDynamicSQL.class);
List emps = new ArrayList<>();
emps.add(new Employee(null, "smith0x1", "smith0x1@atguigu.com", "1",new Department(1)));
emps.add(new Employee(null, "allen0x1", "allen0x1@atguigu.com", "0",new Department(1)));
mapper.addEmps(emps);
openSession.commit();
}finally{
openSession.close();
}
}