当前位置:网站首页>数据库批量插入数据
数据库批量插入数据
2022-07-02 05:11:00 【@淡 定】
application.properties 中配数据库连接信息进行修改:
spring.datasource.username=root
spring.datasource.password=root
//注意参数参数 rewriteBatchedStatements的配置
spring.datasource.url=jdbc:mysql:///db?serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
//实现层
@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) {
//虽然是一条条插入,但是只用了一个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("一条条插入 SQL 耗费时间 {}", (endTime - startTime));
}
}
边栏推荐
- 将光盘中的cda保存到电脑中
- Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
- Find the subscript with and as the target from the array
- Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
- 关于Steam 教育的知识整理
- There are duplicate elements in leetcode. Go implementation
- The underlying principle of go map (storage and capacity expansion)
- Fabric.js IText设置指定文字的颜色和背景色
- el-cascader回显只选中不显示的问题
- Paddlepaddle project source code
猜你喜欢

el-cascader回显只选中不显示的问题

C case of communication between server and client based on mqttnet

Mathematical knowledge (Euler function)

Differential identities (help find mean, variance, and other moments)

Application of intelligent robot in agricultural ecology

How to configure PostgreSQL 12.9 to allow remote connections

Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing

Black Horse Notes - - set Series Collection

Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced

Cubemx DMA notes
随机推荐
Leetcode basic programming: array
JS interview collection test question 1
[Yu Yue education] autumn 2021 reference materials of Tongji University
Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
函数栈帧的创建和销毁
[high speed bus] Introduction to jesd204b
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
Rhcsa --- work on the fourth day
黑馬筆記---Set系列集合
函数中使用sizeof(arr) / sizeof(arr[0])求数组长度不正确的原因
Fabric.js 自由绘制矩形
06 装饰(Decorator)模式
No logic is executed after the El form is validated successfully
[common error] the DDR type of FPGA device is selected incorrectly
将光盘中的cda保存到电脑中
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
Pytest learning ----- pytest assertion of interface automation testing
Here comes the chicken soup! Keep this quick guide for data analysts
Lm09 Fisher inverse transform inversion mesh strategy