IT/Spring

스프링 AntPathMatcher 사용 예제

바다, 2017. 12. 4. 17:11
반응형

Ant 경로 패턴은 URL mapping 등 경로를 지정할 때,

유용하게 사용할 수 있는 경로 패턴이다.


? : 1개의 문자와 매칭

* : 0개 이상의 문자와 매칭

** : 0개 이상의 디렉토리와 매칭



스프링에서 어느 특정한 경로와 Ant 경로 패턴이 일치하는 지를


확인할 때 사용할 수 있는


org.springframework.util.AntPathMatcher 클래스를 제공하고 있다.




AntPathMatcher 클래스의 사용 방법 예시


boolean match(String pattern, String path)


메서드를 이용하여 path가 pattern에 매칭되는지 확인할 수 있다.



public static void main(String[] args) {
String pattern = "/a/b/c/";
// String pattern = "/a/b/*;
// String pattern = "/a/**";
String path = "/a/b/c/d/e.xml";
         
AntPathMatcher m = new AntPathMatcher();
         
boolean b = m.match(pattern, path);
System.out.println(b);
// 매칭될 경우 true를 리턴한다.
}


반응형

'IT > Spring' 카테고리의 다른 글

[STS4 설치] Spring Tools 4 for Eclipse 설치  (0) 2021.05.04