java - 在 Ibatis 中迭代对象列表

标签 java sql ibatis

我有一个对象列表,我想在其中迭代并访问 ibatis sql 中的特定字段。

例。

public Class Student
{
String id;
String name;
}

我将作为参数传递一个 Student 对象列表(List(Student))
并迭代访问每个对象 bean 的 id。我该怎么做?

最佳答案

foreach 标签就是您要查找的内容。示例:

<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>

参见 user guide有关详细信息,请参阅“动态 sql”一章。

顺便说一句,iBatis 不再开发并被卡住,现在称为“MyBatis”,整个开发团队从 Apache 转移到 new MyBatis home .

关于java - 在 Ibatis 中迭代对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3360070/

相关文章:

php - 将变量从表单传递到下一页并放入sql语句php

java - sqlMapClient.startTransaction() - 案例

sql - 应用参数映射时 iBatis 错误 - 由 SQLException : Cursor is closed 引起

java - @Autowired 基于 application.properties 中的属性

java - Spring mvc,制作菜单数据对象

mysql - 为什么我们需要 SQL 的游标?

sql - 使用 SQL 检测异常间隔

jboss - 从 Web 容器外部访问数据源(通过 JNDI)

java - Eclipse 不列出 Java 包中的类

java - Spring 在上传到服务器时损坏 Excel(xlsx, xls) 文件 (org.apache.poi)