我有一个界面,例如
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoLogged {
boolean query() default false;
}
如何在拦截器实现中获取query
参数?
@Provider
@AutoLogged
public class AutoLoggedInterceptor implements WriterInterceptor {
@Context
private ResourceInfo resourceInfo;
@Override
public void aroundWriteTo(final WriterInterceptorContext context)
throws IOException, WebApplicationException {
try {
final String methodName = this.resourceInfo.getResourceMethod().getName();
BasicAutoLoggedProducer.makeCall(methodName);
} catch (final Exception e) {
e.printStackTrace(System.err);
} finally {
context.proceed();
}
}
}
我在context.getPropertyNames中找不到它。我看到带有getAnnotations方法的注释AutoLogged
。如何从界面中检索参数query
?
答案 0 :(得分:1)
你可以简单地做
AutoLogged annotation = resourceInfo.getResourceMethod().getAnnotation(AutoLogged.class);
if (annotation != null) {
boolean query = annotation.query();
}
“并想要设置参数
query
”
不完全确定你的意思,但如果你的意思是你想在运行时设置值,我不是很确定目的而不确定如何去做。希望你的男人“得到”而不是“set”: - )