获取requestmapping所有的url

历览千载书,时时见遗烈。这篇文章主要讲述获取requestmapping所有的url相关的知识,希望能为你提供帮助。

/** * 测试接口 * @return */ @RequestMapping(value = "https://www.songbingjia.com/android/v1/getAllUrl") @ResponseBody public StringgetAllUrl() { RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class); // 获取url与类和方法的对应信息 Map< RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); List< Map< String, String> > list = new ArrayList< Map< String, String> > (); for (Entry< RequestMappingInfo, HandlerMethod> m : map.entrySet()) { Map< String, String> map1 = new HashMap< String, String> (); RequestMappingInfo info = m.getKey(); HandlerMethod method = m.getValue(); PatternsRequestCondition p = info.getPatternsCondition(); for (String url : p.getPatterns()) { map1.put("url", url); } map1.put("className", method.getMethod().getDeclaringClass().getName()); // 类名 map1.put("method", method.getMethod().getName()); // 方法名 RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition(); for (RequestMethod requestMethod : methodsCondition.getMethods()) { map1.put("type", requestMethod.toString()); }list.add(map1); } String jsonArray = JsonUtil.objectToString(list); return jsonArray; }

展示效果:
【获取requestmapping所有的url】
获取requestmapping所有的url

文章图片


    推荐阅读