mybatis foreach 插入多个list
List<Map> listMap = new ArrayList<Map>();
String[] str1 = dept.getCombineId();
String[] str2 = dept.getTestType();
for (int i=0;i<str1.length;i++) {
Map map = new HashMap();
map.put("combineId",str1[i] );
map.put("testType",str2[i] );
listMap.add(map);
}sysDeptDao.insertDeptCombine(dept.getDeptId(),listMap);
dao层
@Insert("<script> insert into dep_dept_combine (dept_id,combine_id,test_type) " +
" <foreach collection='listMap' item='map' index='index' > \n" +
" select #{deptId},#{map.combineId},#{map.testType}" +
" <if test='index != (listMap.size() -1 )'> union all </if> \n" +
" </foreach> </script>")
void insertDeptCombine(@Param("deptId")String deptId,@Param("listMap")List<Map> listMap);