切面配置类,获取切面上的各种属性:
示例
@Aspect
@Component
public class ProceedingJoinPointDemo {
@Pointcut("execution(public * .*.*.*(..))")
public void allControllerMethod() {
}
@SuppressWarnings("rawtypes")
@Around("allControllerMethod()")
public Object aroundMethod(ProceedingJoinPoint point) throws Throwable {
//拦截的实体类
Object target = ();
//拦截的方法名称
String methodName = ().getName();
//拦截的方法参数
Object[] args = ();
//拦截的放参数类型
Class[] parameterTypes = ((MethodSignature)()).getMethod().getParameterTypes();
Method m = null;
try {
//通过反射获得拦截的method
m = ().getMethod(methodName, parameterTypes);
//如果是桥则要获得实际拦截的method
if(()){
for(int i = 0; i < ; i++){
//获得泛型类型
Class genClazz = (());
//根据实际参数类型替换parameterType中的类型
if(args[i].getClass().isAssignableFrom(genClazz)){
parameterTypes[i] = genClazz;
}
}
//获得parameterType参数类型的方法
m = ().getMethod(methodName, parameterTypes);
}
//放参数
Integer userId = ();
Integer ownerCode = ();
String userName = ();
Integer userType = ();
String partnerId = ();
AdminUserVo userVo = new AdminUserVo();
(userId);
(ownerCode);
(userName);
(userType);
(partnerId);
args[1] = userVo;
Object proceed = (args);
} catch (SecurityException e) {
();
} catch (NoSuchMethodException e) {
();
}
return proceed;
}
}
参考博文:/chaoba/p/