1. Define a PointCut:

Note: @pointcut represents the PointCut and value represents the scope of the PointCut

2. Define an Aspect:

Annotation: @aspect declares a section; Before, @around enhancements: @Afterreturning is called Before and after a method is properly executed; AfterThrowing enhancements: @Afterthrowing is executed when a method exits properly. @after is executed when a method throws an exception, and final enhancements are executed whether it throws an exception or exits normally

In the @around annotation method, the proceed() method must say, and the proceed() method will call the urL-triggered controller layer method.






That is, both @afterThrowing and @around annotations call writeContent() to handle normal or abnormal results to the front end. It is equivalent to handing data processing, exception processing, log processing, etc. of controller layer to the front end to be handled by AOP, and it only needs to be written once, so it can be shared by all controller layer code. No more repetitive data handling, exception handling, log handling, etc., in each controller, in each method.

3. Controller test

4. Normal operation results:

5. Abnormal operation results:

Conclusion:
Using AOP to process, so that the development only focus on business logic, no longer repeat each URL request data processing, exception handling, try catch, log.









Think it’s good, give it a thumbs up! Thank you very much!