Home > Back-end > Whether mybatis custom interceptors can get custom annotations
Whether mybatis custom interceptors can get custom annotations
Time:09-28
Diagram method is mybatis Mapper interfaces in one way to have a custom annotation Whether can be obtained in mybatis interceptor to this comments? O great god answer
CodePudding user response:
AOP is inside method. The getAnnotation (. Clazz)
CodePudding user response:
I am using is aop, didn't try in the interceptor, Interface s=method. GetAnnotation (interface. Class);
CodePudding user response:
Test, and can be
@ Target (ElementType METHOD) @ Retention (RetentionPolicy RUNTIME) @ Documented Public @ interface NoFilter { A String value (the default) ""; }
@ Override Public Object intercept (Invocation Invocation) throws Throwable { //final Executor Executor=(Executor) invocation. GetTarget (); The final Object [] args=invocation. GetArgs (); Final MappedStatement MappedStatement=(MappedStatement) args [0]. The final Object parameter=args [1]. Final RowBounds RowBounds=(RowBounds) args [2]. String namespace=mappedStatement. GetId (); String className=namespace. The substring (0, the namespace. The lastIndexOf (". ")); String methedName=namespace. The substring (namespace. LastIndexOf (". ") + 1, the namespace. The length ()); Method [] ms=Class. Class.forname (className.) getMethods (); For (Method m: ms) { If (m.g etName (.) the equals (methedName)) { The Annotation of the Annotation=m.g etAnnotation (NoFilter. Class); System. The out. Println (annotation. The toString ()); }; } }