如何在iBATIS中使用IN子句? [英] How to use an IN clause in iBATIS?

查看:150
本文介绍了如何在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);

这篇关于如何在iBATIS中使用IN子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆