2021-03-13-SpringBoot realizes transaction management

Preface

  • Transaction management: If a method implements transaction management, assuming that this method has 3 operations to insert data, then these 3 insert operations must be performed without errors until the last line of code of this method. Once a certain code appears, such as the first If the 3 insert operations are wrong, the first two insert operations will also give up the insert. In summary: All operations in this method are conjoined babies.
  • If a class implements transaction management, then all methods of this class implement transaction management

step 1

  • Add the @EnableTransactionManagement annotation to the main startup class, which is used to open the transaction management mechanism of the project

Insert picture description here

Step 2 (choose 1 from 2)

  • @Transactional
  • Annotation on the class: This annotation is added to the class, which is equivalent to adding transaction management to all methods in this class

Insert picture description here

  • Annotation on the method: indicates that this method has transaction management
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41270550/article/details/113971603