Reflections contains a lot of scanner, that is, the scanner, call the corresponding method needs to have a configuration corresponding to the scanner, or the program will throw an exception.
Scanner structure:
When used, we mainly use the reflections class to invoke.
Reflections a portion of the scanner is configured by default,
However, in the actual use of the need to add a lot of scanners, can be based on the exceptions thrown by the program to add a corresponding scan
How to use:
New New New New New Methodparameternamesscanner ());
Indicates the scanned package path and configures the scanner
1. Get all classes with action annotations
set<class<?>> classes = Reflections.gettypesannotatedwith (Action. Class); for (class<?> action:classes) { = action.getannotation (requestmapper. Class); + "=requestmapper==" + Request.value ()); }
2. Get all the methods with Requestmapper annotations
Set<method> methods = Reflections.getmethodsannotatedwith (Requestmapper. Class); for (method Method:methods) { + "=methods==" + Reflections.getmethodparamnames (method)); }
Gets the parameter name of a method: (There is no corresponding method in the JDK)
Reflections.getmethodparamnames
Java Reflector Toolkit Reflections