最近项目需要做一个功能,是给设备做签到功能的。相当于身份验证的东西,如果没有签到,就不能调用其他接口。项目原来的同事是先写一个验签方法,在需要验证签到的方法里面调用。这样一来就很麻烦,如果接口很多的话写起来真费劲。于是我就改成用AOP的方式处理。如下,定义一个切面
@Component
@Aspect
public class SignCheck {
@Pointcut("execution(* com.api.web.ScialController.*(..)) " +
"|| execution(* com.api.web.PaymentController.*(..))" +
"|| execution(* com.api.web.BankController.*(..))" +
"|| execution(* com.api.web.QueryControl.*(..))" +
"|| execution(* com.api.web.SendMessageController.*(..))")
public void chechSign() {}
@Before("chechSign()")
public void before(JoinPoint joinPoint) throws RestServiceException {
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof BaseRq) {