千家信息网

mybatis批量插入(Oracle)

发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,配置文件(Oracle):insert into ce_tempPhone_info(phone)(select #{item,jdbcType=VARCHAR} fro
千家信息网最后更新 2025年02月03日mybatis批量插入(Oracle)
  1. 配置文件(Oracle):

insert into ce_tempPhone_info(phone)

(

select #{item,jdbcType=VARCHAR} from dual

)

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

  1. 解析:

    1. parameterType

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

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

    2. collection

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

      2. 数组类型,此处array

    3. item

      1. 循环的时候的变量;

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

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

    4. index

      1. 索引;

    5. open

      1. 查询以什么开始;

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

    1. close

      1. 以什么符号结束;

    2. separator

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

  2. Java类:

Ce_sample_info info = new Ce_sample_info();

info.setProject_id(project_id);

for(int i=0;i

info.setPhone(phones[i]);

//查询当前project_idphonece_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);

}

}


0