範例一

網址:http://stackoverflow.com/questions/1637825/how-to-use-an-in-clause-in-ibatis

Here's a blog post that answers your question:

iBatis: Support for Array or List Parameter with SQL IN Keyword

<selectid="select-test"resultMap="MyTableResult"parameterClass="list">
select * from my_table where col_1 in
  <iterateopen="("close=")"conjunction=",">
   #[]#
  </iterate></select>

And in Java you should pass in a java.util.List. E.g.

List<String> list =newArrayList<String>(3);
list.add("1");
list.add("2");
list.add("3");List objs = sqlMapClient.queryForList("select-test",list);

 

範例二

網址: https://mybatis.github.io/mybatis-3/dynamic-sql.html

<select id="selectPostIn" resultType="domain.blog.Post">
  SELECT *
  FROM POST P
  WHERE ID in
  <foreach item="item" index="index" collection="list"
      open="(" separator="," close=")">
        #{item}
  </foreach>
</select>

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JoshS 的頭像
    JoshS

    JoshS的部落格

    JoshS 發表在 痞客邦 留言(0) 人氣()