Package Demo
Import Java.lang.reflect.Method;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Com.demo.controller.TicketController;
/**
* Document Description: Get the value of requestmapping by reflection
* Author: Zhao Peng
* Time: 2016-10-8-09:04:53
*/
public class Test {
/**
* Method Description: Main method Test
* Author: Zhao Peng
* Time: 2016-10-8-09:04:53
*/
public static void Main (string[] args) {
Get bytecode file "only need to change controller class name"
class<?> clazz = Ticketcontroller.class;
Get the method
Method[] methods = Clazz.getdeclaredmethods ();
for (Method method:methods) {
Determine if a requestmapping comment exists
Boolean present = Method.isannotationpresent (Requestmapping.class);
if (present) {
Get requestmapping comments
requestmapping annotation = method.getannotation (Requestmapping.class);
Output annotation requestmapping contains information (headers=[], name=, path=[], Value=[toticket], produces=[], method=[], params=[], Consumes=[])
System.err.println (annotation);
Get array of value
string[] Value = Annotation.value ();
for (String String2:value) {
Output value
System.out.println (string2);
}
}
}
}
}
Get spring's requestmapping value value by reflection