MyBatis中in的使用

  通常在SQL中使用in关键字可以直接书写范围列表,不过在MyBatis中没有这样支持的语法了,必须要通过foreach标签来实现,示例如下所示:

-- 输入参数是List类型
<select id="selectSomeField" resultMap="java.lang.String">
   SELECT some_col
   FROM table_name
   WHERE col1_name IN
    <foreach collection="list"  item="tmp" index="index" open="(" close=")" separator=",">
         #{tmp}
    </foreach>
</select>


-- 输入参数是Array类型
<select id="selectSomeField" resultMap="java.lang.String">
   SELECT some_col
   FROM table_name
   WHERE col1_name IN
    <foreach collection="array" item="tmp" index="index" open="(" close=")" separator=",">
         #{tmp}
    </foreach>
</select>

 

上一篇:C++异常重抛出


下一篇:FabricJavaPool