获取Java中注释的参数值 [英] Get value of a parameter of an annotation in Java
本文介绍了获取Java中注释的参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个代码:
@Path("/foo")
public class Hello {
@GET
@Produces("text/html")
public String getHtml(@Context Request request, @Context HttpServletRequest requestss){
...
}
我使用AspectJ来捕获对 getHtml的所有调用
方法。我想在我的建议中将参数传递给 @Produces
和 @Path
,即/ foo
和text / html
在这种情况下。我怎么能用反射来做呢?
I am using AspectJ to catch all calls to getHtml
method. I would like to get parameters passed to @Produces
and to @Path
in my advice, i.e. "/foo"
and "text/html"
in this case. How can I do it using reflection ?
推荐答案
获取 @Path $ c的值$ c>参数:
String path = Hello.class.getAnnotation(Path.class).value();
同样,持有方法
getHtml
Method m = Hello.class.getMethod("getHtml", ..);
String mime = m.getAnnotation(Produces.class).value;
这篇关于获取Java中注释的参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文