zoukankan      html  css  js  c++  java
  • java批量插入sql

    控制器

        // 批量插入导出记录
            int[] list = StringProcesser.toIntArray(idStr);
            List<ExportResource> ERLists = new ArrayList<>();
            for (int id : list) {
                ExportResource exportResource = new ExportResource();
                exportResource.setUserId(userId);
                exportResource.setResourceId(id);
                exportResource.setCreateTime(TimeProcesser.getUnixTime());
                ERLists.add(exportResource);
            }
            exportResourceManager.save2Db(ERLists);
    ExportResourceManager
    @Autowired
        private IExportResourceDao iExportResourceDao;
        
    
        public void save2Db(List<ExportResource> exportResource){
            iExportResourceDao.insertCollectList(exportResource);
        }
    IExportResourceDao

    @Insert({
                "<script>",
                "insert into res_export_records(userId, resourceId, createTime) values ",
                "<foreach collection='exportResource' item='item' index='index' separator=','>",
                "(#{item.userId}, #{item.resourceId}, #{item.createTime})",
                "</foreach>",
                "</script>"
        })
        int insertCollectList(@Param(value = "exportResource") List<ExportResource> exportResource);
  • 相关阅读:
    每日一题20180325
    Linux下MySQL表名区分大小写
    CentOS删除编译安装的Python3
    HTTPS配置
    测试 js 方法运行时间(转)
    使用dbutils进行批处理
    oracle生成主键
    JDBC学习笔记(10)——调用函数&存储过程(转)
    easyui Draggable
    blob
  • 原文地址:https://www.cnblogs.com/todarcy/p/12667457.html
Copyright © 2011-2022 走看看