mybatis中批量插入数据(oracle数据库)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36336003/article/details/81706659

oracle数据库中批量插入中:

insert into STUDENT(NAME, SEX, AGE)
select '张三', '男', '12' from dual union all
select '李四', '男', '23' from dual union all
select '小明', '女', '17' from dual;

mybatis中批量插入:

  • 映射文件写法:
<insert id ="insertAll" parameterType="list" >
  insert into STUDENT(NAME, SEX, AGE)
  <foreach collection ="list" item="item" index="index" separator="union all">
    select
#{item.name,jdbcType=VARCHAR}, #{item.sex,jdbcType=VARCHAR},#{item.age,jdbcType=DECIMAL}
    from dual
  </foreach >
</insert>
  • mapper接口方法写法:
void insertAll(List<Map<String, Object>> list);//没有实体类
或:
void insertAll(List<Student> list);//有实体类

猜你喜欢

转载自blog.csdn.net/qq_36336003/article/details/81706659