Spring iBatis 2.3.0中的传递列表参数
我正在尝试将Long类型的列表传递给我的IBatis xml文件。代码如下: Java调用:Spring iBatis 2.3.0中的传递列表参数,spring,mybatis,ibatis,Spring,Mybatis,Ibatis,我正在尝试将Long类型的列表传递给我的IBatis xml文件。代码如下: Java调用: 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上定义为: 从a-id列表中应该传递学生id的学生中
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上定义为:
从a-id列表中应该传递学生id的学生中选择*
实现这一点的最佳方式是什么。请帮忙。我正在使用iBatis 2.3.0。我不明白您为什么需要传递HashMap。您可以直接传递学生ID列表,如下所示
public List<Student> getStudents(List<String> list);
您的映射器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>
我不明白你为什么要通过HashMap。您可以直接传递学生ID列表,如下所示
public List<Student> getStudents(List<String> list);
您的映射器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>