当前位置:网站首页>Database batch insert data
Database batch insert data
2022-07-02 05:16:00 【@Calm down】
application.properties Modify the connection information of China configuration database :
spring.datasource.username=root
spring.datasource.password=root
// Pay attention to Parameters parameters rewriteBatchedStatements Configuration of
spring.datasource.url=jdbc:mysql:///db?serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
// Implementation layer
@Service
public class UserService extends ServiceImpl<UserMapper, User> implements IUserService {
private static final Logger logger = LoggerFactory.getLogger(UserService.class);
@Autowired
UserMapper userMapper;
@Autowired
SqlSessionFactory sqlSessionFactory;
@Transactional(rollbackFor = Exception.class)
public void addUserOneByOne(List<User> users) {
// Although it is inserted one by one , But only one sqlsession
SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);
UserMapper um = session.getMapper(UserMapper.class);
long startTime = System.currentTimeMillis();
for (User user : users) {
um.addUserOneByOne(user);
}
session.commit();
long endTime = System.currentTimeMillis();
logger.info(" Insert... One by one SQL Time consuming {}", (endTime - startTime));
}
}
边栏推荐
- 4. Flask cooperates with a tag to link internal routes
- Paddlepaddle project source code
- Fabric.js 将本地图像上传到画布背景
- 函数中使用sizeof(arr) / sizeof(arr[0])求数组长度不正确的原因
- MMAP zero copy knowledge point notes
- C case of communication between server and client based on mqttnet
- 在{{}}中拼接字符
- php/js cookie共享跨域的问题
- Lay the foundation for children's programming to become a basic discipline
- 从数组中找出和为目标的下标
猜你喜欢

Mathematical knowledge -- understanding and examples of fast power
![Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]](/img/1e/cf0aa09c2fce2278386f12eae4a6cd.jpg)
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]

How to configure PostgreSQL 12.9 to allow remote connections

C# 基于MQTTNet的服务端与客户端通信案例

Solution: the agent throws an exception error

【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘

6.网络-基础

数据库问题汇总

黑马笔记---Set系列集合

创新永不止步——nVisual网络可视化平台针对Excel导入的创新历程
随机推荐
Johnson–Lindenstrauss Lemma(2)
Gee series: unit 9 generate sampling data in GEE [random sampling]
How to make an RPM file
7.1模拟赛总结
MMAP zero copy knowledge point notes
Mathematical knowledge (Euler function)
Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
Fabric.js 3个api设置画布宽高
7.1 simulation summary
Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line
The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
Fabric.js 居中元素
leetcode存在重复元素go实现
Preparation for writing SAP ui5 applications using typescript
Application d'un robot intelligent dans le domaine de l'agroécologie
摆正元素(带过渡动画)
Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]
Pyflink writes MySQL examples with JDBC
CubeMx DMA笔记