如何在jersey WriterInterceptor实现中获取@interface参数

我有一个界面,例如

@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

你可以干脆做

 AutoLogged annotation = resourceInfo.getResourceMethod().getAnnotation(AutoLogged.class); if (annotation != null) { boolean query = annotation.query(); } 

“并希望设置参数query

不完全确定你的意思,但如果你的意思是你想在运行时设置值,我不是很确定目的,也不确定如何去做。 希望你的男人“得到”而不是“集” 🙂