Spring boot项目获取所有请求路径

时间:2025-04-20 22:41:43
 @GetMapping("/getAllUrl")
    public void getAllUr(HttpServletResponse response) throws Exception {
        RequestMappingHandlerMapping mapping = ();
        Map<RequestMappingInfo, HandlerMethod> map = ();

        List<List> sheetData = new ArrayList<>();

        Set<RequestMappingInfo> requestMappingInfos = ();
        for(RequestMappingInfo requestMappingInfo: requestMappingInfos) {
            List<String> rowData = new ArrayList<>();

            // beanName
            HandlerMethod handlerMethod = (requestMappingInfo);
            (().toString());

            // 全路径
            String fullClassPath = ().getName();
            (fullClassPath);

            // 请求地址
            Set<String> patterns = ().getPatterns();
            for(String url :patterns) {
                (url + " ");
            }

            // 请求方式
            Set<RequestMethod> requestMethods = ().getMethods();
            for(RequestMethod requestMethod: requestMethods) {
                (() + " ");
            }

            (rowData);
        }
        // todo 写入excel
    }