AntPathMatcher uses

Hits: 0

Table of contents

ant matching rules


character wildcard description

   ? matches a character

   *          matches 0 or more characters

   ** matches zero or more directories

Official example:

    Matches: com/test.jsp , com/tast.jsp , com/txst.jsp

    Match: all .jsp files in the com folder

    Match: all .jsp files in the com folder and subfolders,

    Match: All .jsp files in the org/springframework folder and subfolders

    matches: org/springframework/servlet/bla.jsp,

PathMatcher interface method explanation (AntPathMatcher implements PathMatcher interface)

Description: Mainly to judge whether the pattern matches, and to parse out the parameters in the path

package org.springframework.util;

public interface PathMatcher {

     * Determine whether the incoming path can be used as a pattern
    boolean isPattern(String path);

     * use pattern to match path
    boolean match(String pattern, String path);

     * If the name, whether to start a partial match
    boolean matchStart(String pattern, String path);

     * Extract the matching part in the path, such as pattern(myroot/*.html), path(myroot/myfile.html), return myfile.html
    String extractPathWithinPattern(String pattern, String path);

     * Extract the matched part in the path, but this side also needs to be paired with a placeholder as a map,
     * Such as pattern(/hotels/{hotel}), path(/hotels/1), parse out "hotel"->"1"
    Map<String, String> extractUriTemplateVariables(String pattern, String path);

     * Provide comparator
    Comparator<String> getPatternComparator(String path);

     * merge pattern, pattern1 and then pattern2
    String combine(String pattern1, String pattern2);


The URL is successfully matched for the first time, and will no longer be matched downwards. At present, it is found that Shiro is like this

filterChainDefinitionMap.put("/**", "user,kickout,onlineSession,syncOnlineSession");
filterChainDefinitionMap.put("/login", "anon,captchaValidate");

For example, the above code, because it /**is in the front, is used to match all paths. According to the above principles, the latter /loginwill never be matched.

You may also like...

Leave a Reply

Your email address will not be published.