如何在iBATIS中使用IN子句?

如何在iBATIS中使用IN子句?

问题描述:

我正在使用 iBATIS 来创建select语句。现在我想用iBATIS实现以下SQL语句:

I'm using iBATIS to create select statements. Now I would like to implement the following SQL statement with iBATIS:

SELECT * FROM table WHERE col1 IN ('value1', 'value2');

使用以下方法,语句未正确准备且没有结果返回:

With the following approach, the statement is not prepared correctly and no result returns:

SELECT * FROM table WHERE col1 IN #listOfValues#;

iBATIS似乎重组了这个列表并尝试将其解释为字符串。

iBATIS seems to restructure this list and tries to interpret it as a string.

我如何正确使用IN子句?

How can I use the IN clause correctly?

这是一篇回复你的博文问题:

Here's a blog post that answers your question:

iBatis:使用SQL IN关键字支持数组或列表参数

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




在Java中你应该传入
java。 util.List。例如,

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



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