@Autowired
DataSourceProperties dataSourceProperties; @Autowired
ApplicationContext applicationContext;
public List<SubjectKycFileVO> batch() {

        // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
DataSource dataSource = applicationContext.getBean(DataSource.class);
// dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
// dataSource.setUrl("jdbc:mysql://localhost:3306/leasing-boot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong&nullCatalogMeansCurrent=true");
// dataSource.setUsername("root");
// dataSource.setPassword("root");
String sql = " INSERT INTO sj_kyc_file (id, createdAt, modifiedAt, createdBy, modifiedBy, version, isDelete, companyId, subjectId, numericalOrder, fileName, filePath, uploadDate) " +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
JdbcTemplate batchUpdate = new JdbcTemplate(dataSource);
// batchUpdate.setDataSource(dataSource);
List<SubjectKycFile> list = new ArrayList<>();
String currentUserId = super.getCurrentAuditor().get();
LocalDateTime now = LocalDateTime.now();
List<Object[]> objectList = new ArrayList<>();
for (int i = 0; i < 10000; i++) {
SubjectKycFile subjectKycFile = new SubjectKycFile();
subjectKycFile.setCreatedAt(now);
subjectKycFile.setModifiedAt(now);
subjectKycFile.setCreatedBy(currentUserId);
subjectKycFile.setModifiedBy(currentUserId);
subjectKycFile.setIsDelete(0);
subjectKycFile.setVersion(0);
subjectKycFile.setId(UUID.randomUUID().toString());
subjectKycFile.setCompanyId("26e5bacb-e3d3-49a9-92a2-1252068ebd66");
subjectKycFile.setNumericalOrder(i);
subjectKycFile.setFileName("" + i);
subjectKycFile.setFilePath("" + i);
subjectKycFile.setUploadDate(LocalDate.now());
subjectKycFile.setSubjectId("2a90f646-c47f-43a5-87c8-5c7f945b7b69");
list.add(subjectKycFile);
}
for (SubjectKycFile subjectKycFile : list) {
objectList.add(new Object[] { subjectKycFile.getId(), subjectKycFile.getCreatedAt(),subjectKycFile.getModifiedAt(),subjectKycFile.getCreatedBy(),subjectKycFile.getModifiedBy()
,subjectKycFile.getVersion(),subjectKycFile.getIsDelete(),subjectKycFile.getCompanyId(),subjectKycFile.getSubjectId(),subjectKycFile.getNumericalOrder(),subjectKycFile.getFileName()
,subjectKycFile.getFilePath(),subjectKycFile.getUploadDate()});
}
batchUpdate.batchUpdate(sql, objectList);
return null;
}
package com.cloudkeeper.leasing.subject.domain;

import com.cloudkeeper.leasing.base.constant.BaseConstants;
import com.cloudkeeper.leasing.base.domain.SubjectBaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate; import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime; /**
* kyc附件
* @author lixin.shao
*/
@ApiModel(value = "kyc附件", description = "kyc附件")
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "sj_kyc_file")
public class SubjectKycFile { @Id
@GeneratedValue(generator = "idGenerator")
@GenericGenerator(name = "idGenerator", strategy = "uuid2")
@Column(length = 36)
@ApiModelProperty(value = "主键id", position = 1)
private String id; /** 创建时间 */
@CreatedDate
@ApiModelProperty(value = "创建时间", position = 2)
private LocalDateTime createdAt; /** 更新时间 */
@LastModifiedDate
@ApiModelProperty(value = "更新时间", position = 3)
private LocalDateTime modifiedAt; /** 创建人 */
@Column(length = 36)
@CreatedBy
@ApiModelProperty(value = "创建人", position = 4)
private String createdBy; /** 更新人 */
@Column(length = 36)
@LastModifiedBy
@ApiModelProperty(value = "更新人", position = 5)
private String modifiedBy; /** 版本(乐观锁) */
@Version
@ApiModelProperty(value = "版本(乐观锁)", position = 6)
private Integer version; /** 逻辑删除 */
@ApiModelProperty(value = "逻辑删除", position = 7)
private Integer isDelete = BaseConstants.Boolean.FALSE.ordinal(); /** 公司id */
@ApiModelProperty(value = "公司id", position = 8)
@Column(length = 36)
private String companyId; /** 案件id*/
@ApiModelProperty(value = "案件id", position = 9)
@Column(name = "subjectId", length = 36)
private String subjectId; /** 案件*/
@ApiModelProperty(value = "案件")
@ManyToOne
@JoinColumn(name = "subjectId", updatable = false, insertable = false)
@JsonIgnore
private Subject subject; /** 序号 */
@ApiModelProperty(value = "序号", position = 10)
private Integer numericalOrder; /** 文件名称 */
@ApiModelProperty(value = "文件名称", position = 10)
@Column(length = 100)
private String fileName; /** 文件路径 */
@ApiModelProperty(value = "文件路径", position = 10)
@Column(length = 200)
private String filePath; /** 上传时间 */
@ApiModelProperty(value = "上传时间", position = 10)
private LocalDate uploadDate; }

使用jdbcTemplate BatchUpdate批量插入效率慢

rewriteBatchedStatements=true

url: jdbc:mysql://localhost:3306/leasing-boot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong&rewriteBatchedStatements=true

SpringBoot使用JdbcTemplate批量保存的更多相关文章

  1. springboot jpa 批量保存数据--EntityManager和 JpaRepository

    1: 项目里面使用springboo-boot-start-data-jpa操作数据库,通过源码,在repository上继承JpaRepository 可以实现保存操作,其中源码接口为: <S ...

  2. SpringBoot使用JdbcTemplate

    前言 本文是对SpringBoot使用JdbcTemplate操作数据库的一个介绍,,提供一个小的Demo供大家参考. 操作数据库的方式有很多,本文介绍使用SpringBoot结合JdbcTempla ...

  3. 使用SpringBoot-JPA进行自定义的保存及批量保存

    更多精彩博文,欢迎访问我的个人博客 说明 SpringBoot版本:2.1.4.RELEASE java版本:1.8 文中所说JPA皆指spring-boot-starter-data-jpa 使用J ...

  4. .NET DLL 保护措施应用实例(百度云批量保存工具)

    最近做了个小工具,将保护措施思路全部应用到了此工具中. 点我下载   百度云批量保存工具是一款专门用于自动批量保存百度云分享的软件. 本软件特点:1:完全模拟人工操作:2:可以批量保存百度分享的文件( ...

  5. springboot之JdbcTemplate

    springboot可以使用JdbcTemplate进行数据库访问,代码如下 添加pom文件 <parent> <groupId>org.springframework.boo ...

  6. sqlbulkcopy 多表批量保存

    /// <summary> /// 批量保存多表 /// </summary> /// <param name="dt1"></param ...

  7. 使用EntityManager批量保存数据

    @PersistenceContext EntityManager em; 从别的系统中定期同步某张表的数据,由于数据量较大,采用批量保存 JPA EntityManager的四个主要方法 ① pub ...

  8. Howto: 在ArcGIS10中将地图文档(mxd文档)批量保存到之前版本

     Howto: 在ArcGIS10中将地图文档(mxd文档)批量保存到之前版本 文章编号 : 38783 软件: ArcGIS - ArcEditor 10 ArcGIS - ArcInfo 10 A ...

  9. mybatis单笔批量保存

    在上一篇写了接口调用解析返回的xml,并赋值到实体.这一篇主要介绍,如何保存实体数据. 一,xml样例 <?xml version="1.0" encoding=" ...

随机推荐

  1. bi数据可视化平台带来的企业变化

    相信现在互联网的发展,大家有目共睹,在互联网的快速发展下,所产生的数据已经成为庞然大物,各行各业都在进行数据化转型,大数据分析也就成了香饽饽,bi数据可视化平台能够让数据可视化,通过数据分析可以业务人 ...

  2. 只有PC端的报表工具使用太不方便了!有没有好用的手机报表app?

    马上到年底了,签订的销售合同需尽快回款,销售经理此时正在下午出差的出租车上,通过手中的手机他查看了一下今天的回款报表 项目已经进行到了关键期,项目经理正在奔赴项目城市的高铁列车上,项目今天的进度报表已 ...

  3. mongodb之shard分片

    总的 1:在3台独立服务器上,分别运行 27017,27018,27019实例, 互为副本集,形成3套repl set 2: 在3台服务器上,各配置config server, 运行27020端口上 ...

  4. AntBlazor Theme in ABP Framework

    介绍 ABP抽象了主题系统,将已有的UI更改到其他的UI框架非常简单,本文介绍了如何将主题切换为AntBlazor Theme. 源码以及示例在Gihub开源. Lsw.Abp.AntDesignUI ...

  5. 自己创建bmp图像

    随便找一张图片,右键选择打开方式为画图,再在画图中保存为bmp即可 如果要保存为png文件,也可以这样

  6. vue项目npm run dev 报错error in ./src/main.js Module build failed: ReferenceError: Unknown plugin "transform-vue-jsx" specified in......

    问题: vue项目npm run dev运行时报错,如下图:  原因: 缺少组件 解决办法: 安装相应的组件:  npm install babel-plugin-transform-vue-jsx ...

  7. docker入门-docker应用场景和优势

    一.什么是docker Docker是一个使用 Go 语言开发的,并且开源的应用容器引擎,基于LXC(Linux Container)内核虚拟化技术实现,提供一系列更强的功能,比如镜像.Dockerf ...

  8. LGP2233题解

    题目大意 求环上走 \(n\) 步从指定点到达另一指定点,到达指定点后 不得继续移动. 大家都做过P1057传球游戏吧?还记得这道题的思路吗? 设 \(dp[i][j]\) 表示传 \(i\) 次求传 ...

  9. mysql数据库-8.0安装及环境搭建

           1.MySQL8.0 For Windows zip包下载地址 https://dev.mysql.com/downloads/file/?id=476233,进入页面后点击底部&quo ...

  10. Nginx高并发实现原理以及常用的优化手段

    Nginx 是如何实现高并发的? 异步,非阻塞,使用了epoll 和大量的底层代码优化. 如果一个server采用一个进程负责一个request的方式,那么进程数就是并发数.正常情况下,会有很多进程一 ...