In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "Mybatis how to use ExecutorType.BATCH", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Mybatis how to use ExecutorType.BATCH" this article.
Use ExecutorType.BATCH
There are three kinds of ExecutorType built into Mybatis, and the default is simple. In this mode, it creates a new preprocessing statement for the execution of each statement, a single sql; is submitted, while the batch mode reuses the pre-processed statements, and all update statements are executed in batches. Obviously, batch performance will be better. However, the batch mode also has its own problems. For example, in the Insert operation, there is no way to get the self-increasing id before the transaction is committed, which does not meet the business requirements in a certain situation.
The specific usage is as follows
/ / batch save method test @ Test public void testBatch () throws IOException {SqlSessionFactory sqlSessionFactory = getSqlSessionFactory (); / / sqlSession SqlSession openSession = sqlSessionFactory.openSession (ExecutorType.BATCH) that can perform batch operations; / / time before batch save long start = System.currentTimeMillis (); try {EmployeeMapper mapper = openSession.getMapper (EmployeeMapper.class); for (int I = 0; I < 1000) Mapper.addEmp (new Employee (UUID.randomUUID (). ToString (). Substring (0,5), "b", "1"));} openSession.commit (); long end = System.currentTimeMillis (); / / batch save the time after execution System.out.println ("execution time" + (end-start)) / / batch precompile sql once = "set parameters =" 10000 times = "execute 1 time 677 / / non-batch (precompilation = setting parameters = execution) =" 10000 times 1121} finally {openSession.close ();}}
Mapper and mapper.xml are as follows
Public interface EmployeeMapper {/ / bulk save employee Long addEmp (Employee employee);}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.