好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

mybatis批量插入(Oracle)

Oracle ):

<!-- 批量插入临时表 -->

<insert id="insertTempPhoneBatch"parameterType="java.util.HashMap" >

insert into ce_tempPhone_info(phone)

(

<foreach collection="list"item="item" separator="union"opne="" close="" index="">

select #{item,jdbcType=VARCHAR} from dual

</foreach>

)

</insert>

Insert intoce_tempPhone_info(phone) (select xxx from dual union select yyy from dual …..);

解析:

parameterType :

参数的类型可以是 java.util.HashMap 或者 java.util. List

如果传入的类型是 List 的话可以两者都可以使用, List 的会被封装成 Map 类型的;

collection :

如果传入的是 list 集合,则此处写 list ;

数组类型,此处 array ;

item :

循环的时候的变量;

如果传入的是 list 或 array ,则使用的时候直接使用 #{item,jdbcType=VARCHAR} 即可;

如果 list 中泛型是对象的话,必须使用 #{item .phone ,jdbcType=VARCHAR} 类似形式

index :

索引;

open :

查询以什么开始;

如: open="(" ,则该 foreach 会以 "(" 开头;

close :

以什么符号结束;

separator :

连接符,以什么进行每次循环的连接符;

Java 类:

Ce_sample_info info = new Ce_sample_info();

info.setProject_id(project_id);

for(int i=0;i<phones.length;i++){

info.setPhone(phones[i]);

// 查询当前 project_id 和 phone 在 ce_sample_info 表中是否存在,不存在则插入

int count = baseDao.selectOne("ce_sample_infoMapper.queryProjectPhoneCount",info);

System.out.println("==========count===========" +count);

if(count == 0) {

String id =baseDao.selectOne("ce_sample_infoMapper.querySampleSeq");

info.setSample_id(id);

baseDao.insert("ce_sample_infoMapper.insertSelective",info);

}

}


本文出自 “随风” 博客,请务必保留此出处http://fuyanchao.blog.51cto.com/3752384/1654823

mybatis批量插入(Oracle)

标签:mybatis oracle 批量插入

查看更多关于mybatis批量插入(Oracle)的详细内容...

  阅读:27次