mybatis学习(四)

1.传统的for循环插入和批量插入的缺点:

2.mybatis批量添加数据的方法:

<insert id="addPersons">
    insert into person(username,email,gender) VALUES
    <foreach collection="persons" item="person" separator=",">
      (#{person.username},#{person.email},#{person.gender})
    </foreach>
  </insert>-->
//下面这种方法必须 数据库必须开启allowMultiqueries=true
<insert id="addPersons"> <foreach collection="persons" item="person" separator=";"> insert into person(username,email,gender) VALUES (#{person.username},#{person.email},#{person.gender}) </foreach> </insert>

 

posted @ 2019-05-09 15:48  socket强  阅读(88)  评论(0编辑  收藏  举报