对于入参为数组:
public List<Employee> getEmpByForeach3(Integer [] IDs);
我们使collection="array"
<select ID="getEmpByForeach3" resultType="com.gong.mybatis.bean.Employee"> select * from tbl_employee where ID in foreach collection="array" item="item" separator="," open="(" close=")" #{item} </foreach> select>
并直接利用#{}接直接获取对应的值。
Integer [] arr = {1,2,3}; List<Employee> es = mapper.getEmpByForeach3(arr); for(Employee e:es) { System.out.println(e); }
输出:
DEBUG 01-21 16:31:10,332 ==> Preparing: select * from tbl_employee where ID in ( ?,?,? ) (BaseJdbcLogger.java:145) DEBUG 01-21 16:31:10,371 ==> Parameters: 1(Integer),2(Integer),3(Integer) (BaseJdbcLogger.java:145) DEBUG 01-21 16:31:10,433 == Total: 3 (BaseJdbcLogger.java:145) Employee [ID=1,lastname=dema,1)">genderemail=dema@qq.com,1)">dept=null]Employee [ID=2,1)">=jack,1)">=675544321@qq.com,1)">=3,1)">=小红,1)">=0,1)">=xiaohong@qq.com,1)">=null]总结
以上是内存溢出为你收集整理的mybatis动态sql之foreach补充(二)全部内容,希望文章能够帮你解决mybatis动态sql之foreach补充(二)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)