idea-转账案例2-java-Spring-AOP-service层

这篇博客探讨了在Java Spring框架下如何利用AOP实现转账服务。首先介绍了转账接口,接着展示了通过注解方式配置AOP的实现类,然后详细讲解了service.xml配置文件的设置。此外,还提到了使用纯配置文件方式实现AOP,包括对应的实现类和服务配置文件的内容。
摘要由CSDN通过智能技术生成

接口

package cn.csy.account.service;

import java.math.BigDecimal;

public interface AccountService {
   
    public void transBalance(Long from, Long to, BigDecimal balance);
}

使用注解的方式

实现类

import cn.csy.account.mapper.AccountMapper;
import cn.csy.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
/*给方法添加注解,使配置文件可以读取这个方法*/
    /*注意,如果有多个方法,想让那个方法作为切点,那么就在那个方法上加上此注解*/
    /*可以写在方法上,表示这个方法有事务*/
    /*也可以写在类上,表示这个类中的所有方法都有事务*/
    /*@Transactional(propagation = Propagation.REQUIRED)*/
@Transactional(propagation = Propagation.REQUIRED)
public class AccountServiceImpl implements AccountService {
   
    @Autowired
    private AccountMapper accountMapper;
    @Override
    public void transBalance(Long from, Long to, BigDecimal balance) {
   
        accountMapper.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值