• 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);
  • 相关阅读:
    php PDO操作类
    PDO笔记
    修改表中的enum字段
    php四种基础算法:冒泡,选择,插入和快速排序法
    MySQL中UNION和UNION ALL的使用
    02-HTML5新的input属性
    01-HTML5的介绍
    03-body标签中相关标签
    02-body标签中相关标签
    01-html介绍和head标签
  • 原文地址:https://www.cnblogs.com/todarcy/p/12667457.html
Copyright © 2020-2023  润新知