In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "springboot project transaction tag verification problem how to solve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "springboot project transaction tag verification problem how to solve" it!
1. Problem description
Springboot project configuration transaction, used through tags before, the last internal project, because it was used in someone else's code, found that it did not seem to work (and then because there is a framework guarantee, never mind), the new startup project also used, verified, the springboot project under the configuration of two tags on it.
2. Solution 2.1 description
(1) in fact, there are only two tags, one is used in the startup class (@ EnableTransactionManagement), and the other is configured wherever needed (@ Transactional)
(2) solution, randomly find a previous test project, a method includes: save a piece of data to the database and a 1 divided by 0 code, and then see if there is any difference between adding a transaction label
2.2 Code description
(1) controller class
@ ResponseBody @ GetMapping ("/ tstest") public String tstest () {this.userService.tstest (); return "SUCCESS";}
(2) service class
Public void tstest () {/ / Save UserEntity userEntity = new UserEntity (); userEntity.setType (0); userEntity.setOpenid ("1111"); insert (userEntity); / / error, rollback int I = 1Universe 0; System.out.println (I);} 2.3Validation1, no transaction
No transaction label, the code is as above.
(1) empty the database first
(2) execute tstest request
When it is found that the line of insert code is finished, the data is stored in the database.
Then the execution is completed (1 stroke 0). Although the error code is reported, the data still exists in the database, the data is not rolled back, and the consistency is not maintained.
2.4 Verification 2, there are transactions
(1) add two tags, one on the startup class method and the other on the tstest method.
(2) first clear the data and execute it to insert.
It is found that although the execution of the insert code line is completed, there is no data in the database at this time, and then the execution is finished, the code reports an error, the data is rolled back, and there is no data stored in the database, indicating that the transaction plays a role, and the data is rolled back.
Thank you for your reading, the above is the "springboot project transaction tag verification problem how to solve" the content, after the study of this article, I believe you on the springboot project transaction tag verification problem how to solve this problem has a deeper experience, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.