ShardingSphere-事务管理

ShardingSphere事务管理

代码实现

引入依赖

<dependencies>
    <dependency>
        <groupId>io.shardingsphere</groupId>
        <artifactId>sharding-transaction-spring-boot-starter</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>

Service业务接口实现类

@Service
public class UserService implements IUserServer{

    @Autowired
    private UserDao userDao;

     /**
     * 新增操作
     * @ShardingTransactionType注解添加事务管理
     * @param record 记录
     * @return int
     */
    @Transactional(rollbackFor = Exception.class)
    @ShardingTransactionType(TransactionType.XA)
    @Override
    public int insert(UserModel record) {
        return userDao.insert(record);
    }

}
Last Updated 2024/5/24 16:21:58