使用foreach进行批量更新

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", "[email protected]", "1",new Department(1)));
emps.add(new Employee(null, "allen0x1", "[email protected]", "0",new Department(1)));
mapper.addEmps(emps);
openSession.commit();
}finally{
openSession.close();
}
}

转载于:https://www.cnblogs.com/zhangzhiqin/p/8567452.html

你可能感兴趣的:(使用foreach进行批量更新)