@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. jmeter之jsonpath和beanshell联合使用

    目的 下面返回的json字符串中,提取args的值中,最后一个逗号后面的字符串,比如下面就是提取:woLgrKts5s9Q4huajoCGHS {"code":20000,&quo ...

  2. [Java]Thinking in Java 练习2.10

    题目 编写一个程序,打印出从命令行获得的三个参数.为此,需要确定命令行数组中String的下标. 代码 1 public class Ex2_10 { 2 public static void mai ...

  3. [Java]Thinking in Java 练习2.2

    题目 创建一个"Hello, World"程序,用javac进行编译,再用java运行它. 程序 1 public class Ex2_2 { 2 public static vo ...

  4. BI工具是什么,有什么用,怎么用?

    BI工具是什么,有什么用,怎么用?这应该是很多刚刚接触BI工具的读者最开始想了解的问题,经常在看到数据可视化.数据分析.数据仓库和大数据等词汇时会有的摸不着头脑,本次小编就围绕BI工具是什么,有什么用 ...

  5. C# KeyValuePair<TKey,TValue>的用法

    命名空间:System.Collections.Generic 构造函数:public KeyValuePair (TKey key, TValue value); 属性:只读属性 Key ,只读属性 ...

  6. 2019CCPC Final K. Russian Dolls on the Christmas Tree

    题目大意 一棵 \(n(1\leq n\leq 2\times 10^5)\) 个节点以 \(1\) 为根的树,分别求以 \(1\sim n\) 为根的子树中有多少个节点编号连续的段. \(T(1\l ...

  7. Windows下搭建REDIS集群

    Redis集群: 如果部署到多台电脑,就跟普通的集群一样:因为Redis是单线程处理的,多核CPU也只能使用一个核, 所以部署在同一台电脑上,通过运行多个Redis实例组成集群,然后能提高CPU的利用 ...

  8. UOJ191口胡

    UOJ191,你失败的原因只有一个:你没有强制在线. 首先这个序列末位加加减减很烦,于是换成操作树,这样就变成查询链的信息了. 注意到一个向量 \((x_1,y_1)\) 比 \((x_2,y_2)\ ...

  9. 微信网页JSDK接口-wx.chooseImage问题

    wx.chooseImage({count: 1, // 默认9sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有sourceTy ...

  10. 『现学现忘』Docker基础 — 26、Docker镜像分层的理解

    目录 1.分层的镜像 2.加深理解 3.特别说明 1.分层的镜像 我们可以去下载一个镜像,注意观察下载的日志输出,可以看到Docker的镜像是一层一层的在下载. 思考:为什么Docker镜像要采用这种 ...