Home > Back-end >  JAVA annotations parameter is a method of how to execute the method in the AOP and get the result
JAVA annotations parameter is a method of how to execute the method in the AOP and get the result

Time:12-29

Defines an annotation, the code below
 @ Target ({ElementType METHOD, ElementType. TYPE}) 
@ Retention (RetentionPolicy RUNTIME)
@ Inherited
@ Documented
Public @ interface PreVisit {
A String value ();
}

In the Controller using the annotations, pay attention to the annotation method of parameter is a @ pv. HasAccess (' XXXXXX ') :
 @ PreVisit (" @ pv hasAccess (' XXXXXX ') ") 
@ RequestMapping (value="https://bbs.csdn.net/topics/getUser")
Public User getUser (Integer userId) {... Some code... }

Define a Service method, this is annotations when parameter method, the following code
 @ Service (" pv ") 
Public class PageVisit {
Public Boolean hasAccess (String par) {
//some code
Return false or true;
}
}
the question now is:
In an AOP implementation, how to perform parameter methods in the annotation "pv. HasAccess (' XXXXXX ')" and get the results
 @ Aspect 
@ Component
Public class PreVisitAspect {
@ Around (" @ the annotation (preVisit) ")
Public Object around (ProceedingJoinPoint joinPoint, PreVisit PreVisit) throws Throwable {
String value=https://bbs.csdn.net/topics/preVisit.value ().//the value of the value here is @ pv hasAccess (' XXXXXX ')
//how to get here here to perform pv hasAccess (' XXXXXX ') later as a result,
//such as Boolean pvResult=@ pv. HasAccess (' XXXXXX ');//as a result, false or true
After obtaining results//do something...
}
}

@ Around here the parameter annotation can be a method, but don't know is how to implement,
Of course, can be directly used in AOP
 @autowired 
PageVisit pv.

And call it with the around pv. HasAccess (' XXX ')
But such inflexible, because this method may be different places to perform, or multiple methods to write multiple AOP
 @ PreVisit (" @ serviceA. MethodA (' XXXXXX ') ") 
@ PreVisit (" @ serviceB methodB (' XXXXXX ') ")
@ PreVisit (" @ serviceC methodC (' XXXXXX ') ")
.


CodePudding user response:

No one will, to a player,,,

CodePudding user response:

Try the @pointcut

 
* * (the @pointcut (" execution (public.. )))
Private void anyPublicOperation () {}

The @pointcut (" within (com) xyz. Myapp. Trading.. *)
")Private void inTrading () {}

The @pointcut (" anyPublicOperation () & amp; & InTrading () ")
Private void tradingOperation () {}

CodePudding user response:

The @pointcut this just get point of tangency, this I know, I have known point of tangency (as long as you brought this annotation is the point of tangency), is now want to executive brought in the annotations in the AOP method

CodePudding user response:

Get the inside of the annotation @ pv. HasAccess (' XXXXXX ') value, through. () his take apart the rules defined, after through the reflection method calls
  • Related