publicList<Employee>getEmpsByConditionForeach(@Param("ids")List<Integer> ids);<!-- public List<Employee> getEmpsByConditionForeach(@Param("ids")List<Integer> employee);--><selectid="getEmpsByConditionForeach"resultType="com.atguigu.mybatis.bean.Employee">select * from tb1_employee<!--collection:指定要遍歷的集合list類型的參數(shù)會特殊處理封裝在map中,map的key就叫l(wèi)istitem:將當(dāng)前遍歷出的元素賦值給指定的變量#{變量名}就能取出變量的值也就是當(dāng)前遍歷出的元素separator:每個元素之間的分隔符open:遍歷出所有結(jié)果拼接一個開始的字符close:遍歷出所有結(jié)果拼接一個結(jié)束的字符index:索引。遍歷list的時候 index就是索引遍歷map的時候index表示的就是map的key,item就是map的值--><foreachcollection="ids"item="item_id"separator=","open="where id in ("close=")">#{item_id}</foreach></select>
jdbc.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&allowMultiQueries=true
<insertid="addEmps"><foreachcollection="emps"item="emp"separator=";">INSERT INTO tb1_employee(last_name,email,gender,d_id)values(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})</foreach></insert>