Transaction operation in springmvc

There are two types of transactions in spring: declarative transactions and programmatic transactions. Here we mainly talk about declarative transactions.

1. First of all, the page layering needs to be standardized. The controller is only responsible for data interaction with the front end. The logic handler is placed in the service layer, and transaction management belongs to program processing. I think it should be placed in the service layer.

2. Add this configuration to the configuration file as a support for transaction operations.

     <tx:annotation-driven/> is to support transaction annotation (@Transactional)

<tx:annotation-driven transaction-manager="txManager"/>

3. In the method in the service layer, add the following annotations

@Transactional  
public void myService(){
  
}  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324992503&siteId=291194637