获取RequestMapping注解中的属性

识字粗堪供赋役,不须辛苦慕公卿。这篇文章主要讲述获取RequestMapping注解中的属性相关的知识,希望能为你提供帮助。
参考:https://www.cnblogs.com/2013jiutian/p/7294053.html
 
@RequestMapping("/value1")
@Controller
public Class A {
    @RequestMapping("/value2")
    public String method1() {
        return "xxx";
    }
}
 
Annotation classAnnotation = A.class.getAnnotation(RequestMapping.class);
if (classAnnotation != null) {
    Class clazz = classAnnotation.annotationType();
 
    try {
【获取RequestMapping注解中的属性】        Method path = clazz.getDeclaredMethod("path");
        Method value = https://www.songbingjia.com/android/clazz.getDeclaredMethod("value");
 
        String[] pathArr = (String[]) path.invoke(classAnnotation);
        String[] valueArr = (String[]) value.inivoke(classAnnotation);
    }  catch (Exception e) {
        e.printStackTrace();
    }
}
 
Method method1 = A.class.getMethod("method1");
Annotation method1Annotation = method1.getAnnotation(RequestMapping.class);
...

    推荐阅读