Mybatis-数据插入

 

传统jdbc数据插入

1、在Java代码for循环插入

executeUpdate()

2、批处理方法addBatch(Statement、Prestatement)

addBatch()

executeUpdate()

3、缺点:

1、  插入速度非常慢,需要频繁获取session

2、  代码和SQL耦合大,非业务代码多

Mybatis数据插入

1、foreach标签(使用较多)

只写一条SQL语句,通过拼接SQL语句添加

2、allowMultiQueries=true(MySQL连接属性)+foreach标签

写多条SQL语句,通过MySQL批量添加

3、ExecutorType(常用)

只写一条的SQL语句,通过mybatis批量添加

  在openSession中添加参数ExecutorType.BATCH

猜你喜欢

转载自www.cnblogs.com/thyHome/p/9080579.html