1.自定义注解
2.切面代码
@Pointcut("@annotation(com.wc88.annotation.Lanjie)")
private void pointcutOne(){
}
@Around("pointcutOne()")
public Object doit(ProceedingJoinPoint jp) throws Throwable {
try {
MethodSignature methodSignature = (MethodSignature) jp.getSignature();
Class clzz = methodSignature.getReturnType();
Object obj = clzz.newInstance();
//此注解修饰的接口返回类中都应包含一个返回头类Sub
Sub sub = new Sub();
sub.setErrorNo("000001");
sub.setErrorInfo("wc88");
Field nameField = clzz.getDeclaredField("sub");//ResponseHeader
nameField.setAccessible(true);
// 如果限流了
nameField.set(obj, sub);
return obj;
// 如果没有限流
return jp.proceed();
} catch (Throwable e) {
return jp.proceed();
}
}