In a previous article (juejin.cn/post/691900…) I have written an aop implementation based on annotations, but it is not very granular, and this article will extend the use of annotations based on the previous article.
Scenario: Make an identifier for the Controller.
Why is there a label for a Controller (that is, describing what the Controller does and why is it useful)?
A: When logging, we sometimes need to capture more than the following:
We also need to make an explanation and description for the purpose of our Controller this time.
Then our custom annotations can add attributes:
Get when enhanced:
1. Get your target
Object target = joinPoint.getTarget();
Copy the code
2. Obtain the method identifier object
CodeSignature signature = (MethodSignature) joinPoint.getSignature();
Copy the code
3. Get the method object by reflection
Method method = target.getClass().getMethod(signature.getName(), signature.getParameterTypes());
Copy the code
4. Through Method getAnnotation(Class annotationClass)
StzbLog annotation = method.getAnnotation(StzbLog.class);
Copy the code
Thus, we identified ways to enhance fullness with custom annotations.