zoukankan      html  css  js  c++  java
  • 关于 mybatis 中 in 写法,<foreach collection="xxx" item="xxx" index="index" open="(" separator="," close=")"> 参数详解

    使用 mybatis 时,如果要使用到 in 写法,要使用  foreach ,里面几个参数,看了很多地方,都说的不清不楚,自己最后各种测试,这里详细说下:

    (1)collection = “” ,这个参数是 dao 层(mapper)接口方法里面传过来的集合参数,如果dao 层传的参数只有一个,这里写关键字 list(如果是数组,写 array)

    例子:

      dao 层:User getInfo(List<Integer> user_ids)
           collection = "list"

    如果有多个参数,并且使用了 @Param 注解(import org.apache.ibatis.annotations.Param),则这里要写注解里面的参数!

    例子: dao 层  :User getInfo(@Param("user_ids")List<Integer> user_ids,@Param("xxx")String xxx)

      collection = "user_ids"   

    (2)item = “” ,集合里面的单个值,给下面  #{ } 用

    (3)index = "" ,这个是遍历的下标,举个简单的例子立刻明白,就是平时 for 循环,我们定义的 i 一样

    例子: for(int i = 0 ;i < 10 ; i ++){

       }

    因此这个参数随便定义都可以,有就行

    (4)open  separator  close  这3个比较好理解,就是  ( , , ,) 这样子啦,拼接括号,中间逗号隔开的意思

  • 相关阅读:
    [leedcode 46] Permutations
    [leedcode 45] Jump Game II
    [leedcode 43] Multiply Strings
    [leedcode 42] Trapping Rain Water
    [leedcode 41] First Missing Positive
    [leedcode 40] Combination Sum II
    全排列
    [leedcode 39] Combination Sum
    [leedcode 38] Count and Say
    调和级数求和(分块)
  • 原文地址:https://www.cnblogs.com/xuehuashanghe/p/12882762.html
Copyright © 2011-2022 走看看