> 文档中心 > MyBatis-Plus使用@Insert注解插入List集合方式及说明

MyBatis-Plus使用@Insert注解插入List集合方式及说明


       简明:记录使用@Insert插入List集合的方式及易错地方

1、使用@Insert注解,可不写对应xml配置文件,作用是等价的(注意格式

@Param注解:对应foreach循环接收的参数(必须写)

标签:标记是JavaScript文本,对foreach语句进行解析(必须写)

foreach标签: (1)collection对应@Param注解集合参数   

                        (2)item对应每个集合内的元素

2、易错注意地方

(1)缺少@Param注解(报错foreach无法获取对应集合参数

报错:org.apache.ibatis.binding.BindingException: Parameter 'studentList' not found. Available parameters are [collection, list]

(2)@Insert注解中缺少标签(报错:无法解析foreach

报错:org.apache.ibatis.binding.BindingException: Parameter 'item' not found. Available parameters are [studentList, param1]