历览千载书,时时见遗烈。这篇文章主要讲述获取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】
文章图片
推荐阅读
- 模块和模块化前端开发入门
- robotframework+appium 创建第一条测试用例
- 安卓 垂直SeekBar
- Medical Three Way Stopcock : 3 Application Methods
- android开发FontMetrics的理解
- spring boot的application配置文件
- 1.AutoMapper简单介绍
- 为什么启动类被@SpringBootApplication注解后,就会自动扫描其包内所有被@Component注解的类()
- Android场景 - 005 - App布局查看