Package com.jeeplus.modules.dynamictrace.web;
Import Com.jeeplus.core.web.BaseController;
Import Org.springframework.beans.factory.BeanFactoryUtils;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestMethod;
Import Org.springframework.web.context.WebApplicationContext;
Import Org.springframework.web.context.support.WebApplicationContextUtils;
Import Org.springframework.web.method.HandlerMethod;
Import org.springframework.web.servlet.HandlerMapping;
Import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
Import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
Import Org.springframework.web.servlet.mvc.method.RequestMappingInfo;
Import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
Import Javax.servlet.ServletContext;
Import Javax.servlet.http.HttpServletRequest; Import Java.util.ArraYlist;
Import Java.util.Iterator;
Import java.util.List;
Import Java.util.Map; /** * Mayor's mailbox Controller * @author SLG * @version 2017-10-02/@Controller @RequestMapping (value = "${adminpath}/dynamict Race ") public class Urlmappingcontroller extends Basecontroller {/************************************** First method (more complex) * /Private class Requesttomethoditem {public String Controllern
Ame
Public String methodname;
Public String RequestType;
Public String Requesturl;
Public class<?>[] Methodparmatypes;
Public Requesttomethoditem (String requesturl, String RequestType, String controllername, String requestmethodname,
Class<?>[] methodparmatypes) {this.requesturl = Requesturl;
This.requesttype = RequestType;
This.controllername = Controllername;
This.methodname = Requestmethodname; This.methodparmatypes = Methodparmatypes; }} @RequestMapping (value = "/temp", method = requestmethod.get) Public String index (HttpServletRequest reque
ST) {ServletContext ServletContext = Request.getsession (). Getservletcontext ();
if (ServletContext = = null) {return null;
} webapplicationcontext Appcontext = Webapplicationcontextutils.getwebapplicationcontext (ServletContext); Mapping of request URLs and processing methods list<requesttomethoditem> requesttomethoditemlist = new ARRAYLIST<REQUESTTOMETHODITEM&G
t; (); Get all the requestmapping map<string, handlermapping> allrequestmappings = beanfactoryutils.beansoftypeincluding
Ancestors (Appcontext, Handlermapping.class, True, false); For (handlermapping handlerMapping:allRequestMappings.values ()) {//This project only needs Requestmappinghandlermappi The URL mapping in ng if (handlermapping instanceof Requestmappinghandlermapping) {requestmappinghandlermapping requestmappinghandlermapping = (requestmappinghandle
rmapping) handlermapping;
Map<requestmappinginfo, handlermethod> handlermethods = Requestmappinghandlermapping.gethandlermethods (); For (Map.entry<requestmappinginfo, handlermethod> requestMappingInfoHandlerMethodEntry:handlerMethods.entry Set ()) {Requestmappinginfo Requestmappinginfo = requestmappinginfohandlermethodentry.
Getkey ();
Handlermethod Mappinginfovalue = Requestmappinginfohandlermethodentry.getvalue ();
Requestmethodsrequestcondition methodcondition = Requestmappinginfo.getmethodscondition ();
Patternsrequestcondition patternscondition = Requestmappinginfo.getpatternscondition ();
String requesttype= "";
String Requesturl = ""; for (Requestmethod M:methodconditIon.getmethods ()) {requesttype=m.name ();
For (String s:patternscondition.getpatterns ()) {requesturl=s;
String controllername = Mappinginfovalue.getbeantype (). toString ();
String requestmethodname = Mappinginfovalue.getmethod (). GetName ();
class<?>[] Methodparamtypes = Mappinginfovalue.getmethod (). Getparametertypes ();
Requesttomethoditem item = new Requesttomethoditem (Requesturl, RequestType, Controllername, Requestmethodname,
Methodparamtypes);
Requesttomethoditemlist.add (item);
} break;
} return ""; /************************************* the second method (relatively simple) ************************************************/public Webapplicationcontext Getwebapplicationcontext (ServletContext SC) {
Return Webapplicationcontextutils.getrequiredwebapplicationcontext (SC); @RequestMapping (value = "/geturlmapping", method = requestmethod.get) public String geturlmapping (httpservletre
Quest request) {Webapplicationcontext WC = Getwebapplicationcontext (Request.getsession (). Getservletcontext ());
Requestmappinghandlermapping RMHP = Wc.getbean (Requestmappinghandlermapping.class);
Map<requestmappinginfo, handlermethod> map = Rmhp.gethandlermethods (); for (iterator<requestmappinginfo> iterator = Map.keyset (). iterator (); iterator. Hasnext ();)
{Requestmappinginfo info = Iterator.next ();
Handlermethod method = Map.get (info);
System.out.println (Method.getmethod (). Getdeclaringclass (). toString () + "--");
System.out.println ("Consumescondition" +info.getconsumescondition ());
System.out.println ("Headerscondition" +info.getheaderscondition ()); SysteM.out.println ("Methodscondition" +info.getmethodscondition ());
System.out.println ("Paramscondition" +info.getparamscondition ());
System.out.println ("Patternscondition" +info.getpatternscondition ());
System.out.println ("Producescondition" +info.getproducescondition ());
System.out.println ("============================");
System.out.print (Method.getmethodannotation (Requestmapping.class). params () [0]);
Return ""; }
}