1.controller Method:
@Aspect @Component Public classTimeaspect { @Around ( "Execution (* com.sea.web.controller.usercontroller.* (..))") PublicObject Handlecontrollermethod (proceedingjoinpoint pjp) throws Throwable {System. out. println ("Time aspect start"); //Description: Proceedingjoinpoint can get the value of the passed-in parameter of the called Method//such as: HTTP:LOCALHOST:8080/USER/1//Comtroller Method: Public User getInfo (@PathVarable String ID) object[] args = Pjp.getargs (); for(Object Arg:args) {System. out. println ("Arg is"+ arg);//ID 1 } LongStart =NewDate (). GetTime (); //This object is the return value of the bar method, such as: User user= usercontroller.finduser (), // The method is equivalent to the filter in the Dofilter () method of the object Object = pjp.proceed (); System. out. println ("time aspect:"+ (NewDate (). GetTime ()-start)); System. out. println ("Time aspect End"); return Object; }}
@Around: Contains the following three kinds of
before Advice |
Treatment prior to substitution |
After Advice |
Processing after a call |
Throw Advice |
Exception handling thrown at the time of the call |
Execution com.sea.web.controller.UserController. * (..))
execution : Indicates execution
First *: return value ; This means that whatever the return value is.
Com.sea.web.controller.UserController: denotes that class
Second *: Presentation method: All Methods under Class
*(..) : All methods, methods of any parameters are executed
anotation Annotation Rules:
@Aspect the class that represents the annotation is an abstract service method module;
@Pointcut define the usage rules for the service, which methods the service methods are applied to in the target class.
@Pointcut ("Execution (*add* (..))") The first * indicates whether or not there are return values, all methods that begin with add, regardless of the parameters.
Private Voidaddaddmethod () {}; This method is only an empty method body in the annotation pattern, is a modal method definition structure, the method cannot have a return value, cannot have any parameters, and cannot implement it. The identity of the method name to use in advice.
Advice annotation checksecurity () method, indicating that the method is a specific service method, using annotations, advice does not appear, but using the above mentioned in the theoretical part of the use of @after, @Befor, @Throw to represent, The rules defined in the Pointcut are also associated in advice.
Spring slicing aspect