I struggle with reading the parameters of the RequestMapping
annotation (in result, it doesn't matter what annotation it is). The point is the annotation is placed on the class level.
@RequestMapping(value = "VIEW", params = "moduleCode=" + MyController .MODULE_CODE)
public class MyController {
}
The way I use to obtain those values is briefly described as the answer to a question here.
for (Annotation annotation : MyController.class.getAnnotations()) {
Class<? extends Annotation> type = annotation.annotationType();
System.out.println("Values of @" + type.getName());
for (Method method : type.getDeclaredMethods()) {
try {
Object value = method.invoke(annotation);
System.out.println("-> " + method.getName() + ": " + value);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
The output is the following:
Values of @org.springframework.web.bind.annotation.RequestMapping
-> value: [Ljava.lang.String;@13b1a47
-> method: [Lorg.springframework.web.bind.annotation.RequestMethod;@4f3a2bf2
-> params: [Ljava.lang.String;@741b4580
-> produces: [Ljava.lang.String;@2a70120d
-> headers: [Ljava.lang.String;@23b1293f
-> consumes: [Ljava.lang.String;@440af967
How can I read array parameters of the class level annotation?
Aucun commentaire:
Enregistrer un commentaire