zoukankan      html  css  js  c++  java
  • spring mvc 获取所有注册的url

     背景:坑货同事写代码一点规范都没有,瞎写,根据url没法直接定位到方法,无奈产生了此接口,程序员何苦为难程序员呢

        @Autowired
        private RequestMappingHandlerMapping handlerMapping;
    
        @GetMapping("getUrlMap")
        @ApiOperation(value = "获取所有url映射", notes = "")
        public Object getUrlMap() {
            Map<String, String> retMap = new HashMap<>();
            Map<RequestMappingInfo, HandlerMethod> map = handlerMapping.getHandlerMethods();
            Iterator<Entry<RequestMappingInfo, HandlerMethod>> iter = map.entrySet().iterator();
            Map.Entry<RequestMappingInfo, HandlerMethod> entry;
            while (iter.hasNext()) {
                entry = iter.next();
                if (entry.getValue().getBeanType().getName().contains("com.xf.controller")) {
                    String url = entry.getKey().getMethodsCondition() + "  " + entry.getKey().getPatternsCondition();
                    String method = entry.getValue().getMethod().toString();
                    retMap.put(url, method);
                }
            }
            return JsonRet.successData(retMap);
        }
  • 相关阅读:
    ASP.NET
    JS、JQury
    ASP.NET
    ASP.NET
    ASP.NET
    C#
    C#
    C#
    基础算法-树:预备知识
    开发环境配置--Ubuntu+Qt4+OpenCV(二)
  • 原文地址:https://www.cnblogs.com/wujf/p/10796348.html
Copyright © 2011-2022 走看看