首页 > 编程语言 >java 批量插入

java 批量插入

时间:2022-10-21 12:45:23浏览次数:46  
标签:java 批量 插入 listMap entity equipment equmentEntityList item new

1.在Mapper中

 /**
     * 批量添加实体
     * @param equmentEntityList
     */
    void addBatch(@Param("equmentEntityList") List<EqumentEntity> equmentEntityList);

2.在Mapper.xml

<insert id="addBatch" parameterType="java.util.List">
        INSERT INTO new_equment(
            equipment_code,
            agency_id,
            equipment_name,
            equipment_type,
            equipment_communication,
            equipment_bluetooth,
            equipment_url
        )
        VALUES
        <foreach collection ="equmentEntityList" item="item" separator =",">
            (
            #{item.equipmentCode},
            #{item.agencyId},
            #{item.equipmentName},
            #{item.equipmentType},
            #{item.equipmentCommunication},
            #{item.equipmentBluetooth},
            #{item.equipmentUrl}
             )
        </foreach >
    </insert>

3.在controller

 // 1.用于批量插入
            equmentEntityList = new ArrayList<>();
//3.将excel转换list集合
            List<Map<String,Object>> listMap = new ArrayList<Map<String,Object>>();
            listMap = ExcelUtils.excelToShopIdList(excelFile.getInputStream());
            System.out.println(listMap.size());
            //4.遍历excel集合并组装插入的集合
            for (Map<String, Object> m : listMap)
            {
                entity = new EqumentEntity();
                entity.setEquipmentType(equipmentType);
                entity.setEquipmentCommunication(equipmentCommunication);
                entity.setEquipmentBluetooth(equipmentBluetooth);
                entity.setAgencyId(agencyId);
                entity.setEquipmentCode(m.get("c0").toString());//设备编码
                entity.setEquipmentUrl(m.get("c1").toString());//视频地址
                equmentEntityList.add(entity);
            }
            //5.批量添加
            service.addBatch(equmentEntityList);

 

标签:java,批量,插入,listMap,entity,equipment,equmentEntityList,item,new
From: https://www.cnblogs.com/ckfuture/p/16813080.html

相关文章

  • java版Excel文件导入数据库源代码
       java版Excel文件导入数据库源代码  servlet容器:tomcat(或者其他)数据库:oracle(或者其他)使用框架:jsp+struts1.2支持字符型/数据型/日期型/CLOB等数据使用步骤:1.......
  • javascript 的setTimeOut 中this指向及外部参数传参
    //外部的参数传参数,放到第三项及以后就可以myArray=['zero','one','two'];myArray.myMethod=function(sProperty){consol......
  • ABP vNext 批量操作
    ABP框架6.0后提供了 InsertManyAsync  UpdateManyAsync DeleteManyAsync 批量操作方法源码:publicinterfaceIBasicRepository<TEntity>:IReadOnlyBasicReposi......
  • java报错:cannot resolve method compareTo(java.lang.double)
     排序不正确写法:List<Map<String,Object>>sortList2=list.stream().sorted((o1,o2)->{if(o1.get("DAY_ACTUAL").toString().compareTo(o2......
  • Java命名规范
    Java规范1.命名规范1.类,接口命名大小驼峰命名,单个单词首字母大写(Hello),多个单词每个都大写(HelloWorld)2.变量,方法命名单个单词全部小写,多个单词首字母小写,后面的单词......
  • JavaScript获取两个数组数组的差集
    JavaScript获取两个数组数组的差集JavaScript在ES6中增加了很多Array对象的方法,这让我们在做数组元素操作的时候方便很多。以下便是分别通过Array的some,find,findIndex......
  • JavaScript 设计模式之代理模式
    代理模式,代理(proxy)是一个对象,它可以用来控制对另一个对象的访问。现在页面上有一个香港回归最想听的金典曲目列表:<ulid="container"><li>我的中国心</li><li>东方......
  • Java I/O(4):AIO和NIO中的Selector
    您好,我是湘王,这是我的博客园,欢迎您来,欢迎您再来~ 在Java NIO的三大核心中,除了Channel和Buffer,剩下的就是Selector了。有的地方叫它选择器,也有叫多路复用器的(比如Netty)。......
  • postman使用excel参数批量执行
    第一步,写好连接,报错。参数使用{{name}},这样的划分。保存接口 第二步,找到runner。选择接口所在的文件夹,点击runner   第三步,选择接口和文件  点击run,运行,......
  • java 入土--集合详解
    java集合集合是对象的容器,实现了对对象的常用的操作,类似数组功能。和数组的区别:数组长度固定,集合长度不固定数组可以存储基本类型和引用类型,集合只能存储引用类型使......