@Component
@Aspect
public class PizerAspect {
/**service层切面*/
private final String POINT_CUT = "execution(* project.Service..*(..))";
@Pointcut(POINT_CUT)
private void (){}
@Before(value = "pointcut()")
public void doAfterAdvice(JoinPoint joinPoint) throws ClassNotFoundException {
System.out.println("方法前面");
String targetName = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
Class targetClass = Class.forName(targetName);
Method[] methods = targetClass.getMethods();
String param_a = "";
String param_b = "";
if (methods.length>0){
for (Method method : methods) {
if (method.getName().equals(methodName)) {
if (method.getAnnotation(pizerLog.class)!=null){
param_a = method.getAnnotation(pizerLog.class).param_a();
param_b = method.getAnnotation(pizerLog.class).param_b();
break;
}
}
}
}
//拿到两个参数,再根据自己业务进行二次控制
System.out.println("param_a=="+param_a);
System.out.println("param_b=="+param_b);
}
}
近期评论