What is the difference between /* and /** pattern in Spring boot?

后端 未结 3 1481
自闭症患者
自闭症患者 2021-02-14 14:50

I was trying to register certain URLs for a Filter when I noticed that there is a difference between /* and /** patte

3条回答
  •  伪装坚强ぢ
    2021-02-14 15:25

    there is no /** in registration.addUrlPatterns as we can see in Source code

    private static boolean matchFiltersURL(String testPath, String requestPath) {
    
        if (testPath == null)
            return false;
    
        // Case 1 - Exact Match
        if (testPath.equals(requestPath))
            return true;
    
        // Case 2 - Path Match ("/.../*")
        if (testPath.equals("/*"))
            return true;
        if (testPath.endsWith("/*")) {
            if (testPath.regionMatches(0, requestPath, 0,
                                       testPath.length() - 2)) {
                if (requestPath.length() == (testPath.length() - 2)) {
                    return true;
                } else if ('/' == requestPath.charAt(testPath.length() - 2)) {
                    return true;
                }
            }
            return false;
        }
    
        // Case 3 - Extension Match
        if (testPath.startsWith("*.")) {
            int slash = requestPath.lastIndexOf('/');
            int period = requestPath.lastIndexOf('.');
            if ((slash >= 0) && (period > slash)
                && (period != requestPath.length() - 1)
                && ((requestPath.length() - period)
                    == (testPath.length() - 1))) {
                return testPath.regionMatches(2, requestPath, period + 1,
                                               testPath.length() - 2);
            }
        }
    
        // Case 4 - "Default" Match
        return false; // NOTE - Not relevant for selecting filters
    
    }
    

提交回复
热议问题