传递iBatis 2.3.0中的列表参数

时间:2015-10-30 05:45:08

标签: spring mybatis ibatis

我正在尝试将Long类型的列表传递给我的IBatis xml文件。以下是代码:

Java Call:

List<Long> a; // This contains a list of id's 
Map<String,Object> params = new HashMap<String,Object>();
params.put("iArray",a);

我需要在我的sql中传递这个id列表,在mapper xml上定义为:

从学生中选择*,其中student_id in(a - id的列表应该通过)。

实现此目的的最佳方法是什么。请帮助。我正在使用iBatis 2.3.0。

1 个答案:

答案 0 :(得分:0)

我不明白为什么你需要传递HashMap。您可以直接传递studentIds列表,如下所示。

public List<Student> getStudents(List<String> list);

你的Mapper xml如下所示。

<select id="getStudents" parameterType="list" resultType="Student">
        SELECT * from students where studentId in
        <foreach item="item" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
相关问题