当前位置:网站首页>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));
}
}
边栏推荐
- Leetcode basic programming: array
- Using QA band and bit mask in Google Earth engine
- Feign realizes file uploading and downloading
- Mysql基础---查询(1天学会mysql基础)
- Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
- Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]
- Go Chan's underlying principles
- Gee series: Unit 4 data import and export in Google Earth engine
- Paddlepaddle project source code
- LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)
猜你喜欢
Fabric.js 居中元素
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
LeetCode 1175. 质数排列(质数判断+组合数学)
2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路
[bus interface] Axi interface
Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line
数据库问题汇总
Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
Fabric.js IText设置指定文字的颜色和背景色
随机推荐
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
Lay the foundation for children's programming to become a basic discipline
How to configure PostgreSQL 12.9 to allow remote connections
Global and Chinese market of pressure gauges 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
Black Horse Notes - - set Series Collection
7.TCP的十一种状态集
el-cascader回显只选中不显示的问题
Draw a wave chart_ Digital IC
Fabric.js IText设置指定文字的颜色和背景色
Case sharing | intelligent Western Airport
Paddlepaddle project source code
fastText文本分类
Here comes the chicken soup! Keep this quick guide for data analysts
[bus interface] Axi interface
Collectors. Groupingby sort
Save the CDA from the disc to the computer
National all Chinese Automatic Test Software apifox
国产全中文-自动化测试软件Apifox
Fabric.js 将本地图像上传到画布背景