zoukankan      html  css  js  c++  java
  • mybatis 批量上传

    新建实体类
    BatchModel ins=new BatchModel();
    //把实体类装list里
    List<BatchModel> batchModel = new ArrayList<>();
    for (int i = 0; i < arr.size(); i++) {
    ArrayList<String> row = arr.get(i);
    ins.setA(subFileName);
    ins.setB(row.get(0));
    ins.setC(row.get(1));
    ins.setD(row.get(2));
    ins.setE(row.get(3));
    batchModel.add(ins);
    给实体类赋值
    )
    由于一些数据库的SQL对执行的SQL长度有限制,所以使用foreach元素的时候需要预估对象的长度

    int partsize=80;//每次的数量
    int index=0;//第几条
    int iflg=0;//到几条
    int recordcont=batchModel.size();//获取总数量
    //index<总数量 循环到需要的数量

    for(;index<recordcont;index+=partsize){
    iflg=(index+partsize)>=recordcont ? recordcont:(index+partsize);
    programService.storagekufripackage(batchModel.subList(index,iflg));
    }
    if(recordcont-iflg>0){

    programService.storagekufripackage(batchModel.subList(index,iflg)); //开始插入数据库
    }

    //我用的 spring boot//   加入 @Param("param")注解

    void test(@Param("param") List<BatchModel> batchModels);

    //mybatis 里是sql

    <insert id="test" parameterType="com.cck.model.auxiliary.test">
    insert into ods_groupstock_actual (
    filenames, rowno, typeclass,
    jan, feb, mar, apr,
    may, jun, jul, aug,
    sep, oct, nev, dec,
    total, upload_user
    )
    values
    <foreach collection="param" item="veh" separator=",">
    (
    #{veh.A},#{veh.P}, #{veh.B},
    #{veh.C},#{veh.D}, #{veh.E}, #{veh.F},
    #{veh.G},#{veh.H}, #{veh.I}, #{veh.J},
    #{veh.K}, #{veh.L}, #{veh.M}, #{veh.N},
    #{veh.O}, #{veh.Q}
    )
    </foreach>
    </insert>




  • 相关阅读:
    C++里面关于虚函数的一些注意点
    HDOJ 2736 Surprising Strings
    hdu
    hdu 4404 Worms(多边形与圆的交)
    HTC one/M7电信802d 毒蛇ViperOne2.1.0/高级毒蛇工具/完美root,精简/更多自定义,稳定,流畅ROM
    Replace
    Centos环境下部署游戏服务器-权限
    jdk1.6与1.7垃圾回收
    java--基于socket的网络传输开发
    番外:android模拟器连不上网
  • 原文地址:https://www.cnblogs.com/cjb1/p/10262259.html
Copyright © 2011-2022 走看看