zoukankan      html  css  js  c++  java
  • SpringBoot获取所有接口的路由

        @Autowired
        WebApplicationContext applicationContext;
     
        @RequestMapping(value = "v1/getAllUrl", method = RequestMethod.POST)
        public Object getAllUrl() {
            RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
            // 获取url与类和方法的对应信息
            Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
            
    //      List<String> urlList = new ArrayList<>();
    //      for (RequestMappingInfo info : map.keySet()) {
    //          // 获取url的Set集合,一个方法可能对应多个url
    //          Set<String> patterns = info.getPatternsCondition().getPatterns();
    //
    //          for (String url : patterns) {
    //              urlList.add(url);
    //          }
    //      }
     
            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);
            }
  • 相关阅读:
    大数据究竟能干什么,值得我们好好思考
    大数据入门的四个必备常识
    大数据入门的四个必备常识
    2016年大数据的8个预测
    2016年大数据的8个预测
    大数据和云计算究竟有什么关系?
    大数据和云计算究竟有什么关系?
    linux内核模块依赖图
    Python2.7安装教程
    设置导航栏的相关属性
  • 原文地址:https://www.cnblogs.com/deityjian/p/12533302.html
Copyright © 2011-2022 走看看