Mybatis中foreach对List、实体类、List 的循环

时间:2025-02-16 10:56:40

1、List<Object> 循环

<foreach collection="idList" index="index" item="item" open="(" separator="," close=")">
    #{item}
</foreach>

collection --------  接收的数组(入参)       

index -------- 循环体中的具体对象的序号   item --------  循环体中的具体对象

open --------  开始符号          close --------  关闭符号          separator ------ 分割符号

 

2、实体类、List<Map> 循环

<foreach collection="students" item="student" close=")" open="(" separator=",">
       #{}
</foreach>

collection --------  接收的List<student> 实体类List  或者  List<Map>

item --------  循环体中的student对象或者Map

 -------- 所用对象或者Map 的属性

 

 

2019年08月23日