foreach元素的属性主要有item,index,collection,open,separator,close。
@Test
void contextLoads6() {
ArrayList<OpJoke> objectArrayList = Lists.newArrayList();
objectArrayList.add(new OpJoke(null,"测试1","",new Date()));
objectArrayList.add(new OpJoke(null,"测试2","",new Date()));
opJokeMapper.insertOpJokeList(objectArrayList);
}
Integer insertOpJokeList(@Param("OpJokeList") List OpJokeList);
<insert id="insertOpJokeList">
INSERT INTO `test_yjdsns`.`op_joke`(`name1`, `name2`, `create_time`) VALUES
<foreach item="item" index= "index" open="" separator ="," close="" collection ="OpJokeList" >
(
#{item.name1},
#{index},
#{item.createTime}
)
foreach>
insert>
==> Preparing: INSERT INTO `test_yjdsns`.`op_joke`(`name1`, `name2`, `create_time`) VALUES ( ?, ?, ? ) , ( ?, ?, ? )
==> Parameters: 测试1(String), 0(Integer), 2022-10-20 23:37:46.388(Timestamp), 测试2(String), 1(Integer), 2022-10-20 23:37:46.388(Timestamp)
<== Updates: 2
