引入aop
implementation 'org.springframework.boot:spring-boot-starter-aop'
代码实现
`package com.photo.photoking.interceptor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
@Aspect
@Component
public class AopTest {
@Around("execution(public * com.photo.photoking.api.*.executePhoto1(..)))")
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
Object[] args = proceedingJoinPoint.getArgs();
MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
HandlerMethod handlerMethod = new HandlerMethod(proceedingJoinPoint.getTarget(), methodSignature.getMethod());
MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
for (MethodParameter methodParameter : methodParameters) {
String name = methodParameter.getParameter().getName();
if ("operationType".equals(name)) {
Object value = args[methodParameter.getParameterIndex()];
args[methodParameter.getParameterIndex()] = value + "test!!";
}
}
Object result = proceedingJoinPoint.proceed(args);// 执行切点
return result;
}
}
标签:Object,springboot,aop,get,args,proceedingJoinPoint,springframework,import,org
From: https://www.cnblogs.com/yezhuqishi/p/18224865