@Controller @requestmapping ("/admin/util") public class systemcontroller { private static final logger log = loggerfactory.getlogger (SystemController .class); @RequestMapping (value = "/ Findurimapmethod.do ") @ResponseBody public String Findurimapmethod (Httpservletrequest request, httpservletresponse response) { final env env = envutils.getenv (); final string uri = env.param ("uri", Request.getrequesturi ()); return gethandler (request, uri, "GET"); } private string gethandler ( Httpservletrequest request, final string uRi, string method) { final env env = envutils.getenv (); final string fmethod = method; String[] beanNames = Env.getapplicationcontext (). Getbeannamesfortype (Requestmappinghandlermapping.class); log.info ("requestmappinghandlermapping: {}", arrays.tostring (BeanNames)); HttpServletRequestWrapper httpServletRequestWrapper = new httpservletrequestwrapper (Request) { @Override Public string getrequesturi () { /*stRing paramuri = super.getparameter ("uri"); if (paramuri != null && ! "". Equals (Paramuri.trim ())) { return paramUri; }*/ return uri; } @Override public stringbuffer getrequesturl () { return new stringbuffer (Super.getrequesturl (). toString () .replace ( Super.getrequesturi (), uri)); } @Override public string getservletpath () { return super.getservletpath (). Replace (Super.getRequestURI (), uri); } @Override &NBSP;&NBSP;&NBSp; public string getmethod () { if (fMethod == null | | ". Equals (Fmethod)) { return super.getmethod (); } return fMethod; } }; stringbuilder urimapmethod = new stringbuilder (); urimapmethod.append (Httpservletrequestwrapper.getrequesturi ()). Append (": ["); &nbsP; if (beannames != null) { for (string beanname : beannames) { log.info ("BeanName: {} ", beanname); requestmappinghandlermapping mapping = env.getbean (beanName, Requestmappinghandlermapping.class); try { HandlerExecutionChain chain = Mapping.gethandler (httpservletrequestwrapper); &Nbsp; if (Chain != null) { object handler = chain.gethandler () ; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN (handler); if ( Handler instanceof handlermethod) { handlermethod hm = (Handlermethod) handler; &nbsP; log.info ("{}:{}", hm.getbeantype (). GetName (), HM); Urimapmethod.append (HM); } else if (handler instanceof Org.springframework.web.servlet.mvc.Controller) { org.springframework.web.servlet.mvc.Controller hm = ( Org.springframework.web.servlet.mvc.Controller) handler; class<? extends Org.springframework.web.servlet.mvc.controller> hmclass = hm.getclass (); log.info ("{}:{}", hmclass.getname (), Hmclass.getdeclaredmethod ("HandleRequest", Httpservletrequest.class, httpservletresponse.class)); urimapmethod.append (Hmclass.getdeclaredmethod ("HandleRequest", httpservletrequest.class, Httpservletresponse.class)); } else { urimapmethod.append (Handler.getclass (). GetName ()); } break; } } catch (httprequestmethodnotsupportedexception e) { return GetHandler (httpservletrequestwrapper, uri, "POST"); } catch (exception e) { Log.error ("Get uri mapping error.", e); } /*map<requestmappinginfo, handlermethod> mapmethods = mapping.gethandlermethods (); if (mapmethods != null) { Iterator<Entry<RequestMappingInfo, Handlermethod>> iter = mapmethods.entryset (). Iterator (); while ( Iter.hasnext ()) { entry<requestmappinginfo, handlermethod > entry = iter.next (); requestmappinginfo key = entry.getkey (); handlermethod hm = (Handlermethod) entry.getvalue (); method method = hm.getmethod (); log.info ("{} : {}->{} ", key.getpatternscondition (), &NBSP;KEY,&NBSP;HM); } }*/ } } return urimapmethod.append ("]"). toString (); }}
It is convenient to locate the controller code for spring MVC based on the URI.
A tool class that locates the spring MVC map code based on the URI