zoukankan      html  css  js  c++  java
  • mybatis动态sql之foreach补充(二)

    对于入参为数组:

        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, gender=1, email=dema@qq.com, dept=null]
    Employee [id=2, lastName=jack, gender=1, email=675544321@qq.com, dept=null]
    Employee [id=3, lastName=小红, gender=0, email=xiaohong@qq.com, dept=null]
  • 相关阅读:
    组合与计数
    20160929训练记录
    奇特而有用的定理
    图论 500 题
    《长安十二时辰》愿你看尽世间百态,心中仍有热血
    洛谷 [P1337] 平衡点
    洛谷 [P3496] BLO
    洛谷 [P2341] 受欢迎的牛
    洛谷 [P3723] 礼物
    洛谷 [P3338] 力
  • 原文地址:https://www.cnblogs.com/xiximayou/p/12222244.html
Copyright © 2011-2022 走看看