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

mybatis学习(四)

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>

mybatis学习(四)

 

相关文章:

  • 2022-12-23
  • 2021-12-27
  • 2021-08-26
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-29
猜你喜欢
  • 2021-08-16
  • 2022-01-13
  • 2021-08-14
  • 2021-11-29
  • 2021-11-22
  • 2022-12-23
相关资源
相似解决方案