Spring的AntPathMatcher(路徑匹配)

import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
 
import junit.framework.TestCase;
 
public class AntPathMatcherTest extends TestCase{
     
    public void testMatch() {  
         
        PathMatcher matcher = new AntPathMatcher();  
         
        //徹底路徑匹配  
        //String requestPath="/user/list.htm?username=aaa&id=2&no=1&page=20";
        //String patternPath="/user/list.htm**";
    
        //不完整路徑匹配  
        //String requestPath="/app/pub/login.do";
        //String patternPath="/**/login.do";
          
        //模糊路徑匹配  
        //String requestPath="/app/pub/login.do";
        //String patternPath="/**/*.do";
          
        //模糊單字符路徑匹配  
        String requestPath = "/app/pub/login.do";
        String patternPath = "/**/lo?in.do";
          
        boolean result = matcher.match(patternPath, requestPath);  
         
        assertTrue(result);  
    }  
 
}
相關文章
相關標籤/搜索