Java – how to handle properties in interceptor bindings
•
Java
I have a note:
@Inherited
@InterceptorBinding
@Retention(RUNTIME)
@Target({METHOD,TYPE})
public @interface Example {
}
And interceptor classes for processing:
@Interceptor
@Example
public class ExampleInterceptor implements Serializable {
...
}
I want to add a parameter text:
public @interface Example {
String text();
}
But I don't know how to handle the parameters in the interceptor class How to modify class comments?
@Interceptor
@Example(text=???????)
public class ExampleInterceptor implements Serializable {
...
}
If I write @ example (text = "my text"), I will call the interceptor when I annotate the method / class with @ example (text = "my text") But I want to call the interceptor – @ example (text = "other text") independently on the parameter value
And how to get the parameter value? Do I have to use reflection or do I have a better method?
Solution
When using annotation @ nonbinding, interceptors are called for each attribute value
Notes:
public @interface Example {
@Nonbinding String text() default "";
}
Interceptor:
@Interceptor
@Example
public class ExampleInterceptor implements Serializable {
...
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
