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

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=",">
       #{student.xm}
</foreach>

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

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

student.xm -------- 所用对象或者Map 的属性

 

 

2019年08月23日

 

 

 

 


版权声明:本文为feidi7783原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。