use*_*153 129
Spring框架中匹配的Ant风格路径模式:
映射使用以下规则匹配URL:
?
匹配一个字符*
匹配零个或多个字符**
匹配路径中的零个或多个"目录"{spring:[a-z]+}
将regexp[a-z]+
与名为"spring"的路径变量相匹配一些例子:
com/t?st.jsp
- 匹配com/test.jsp但也com/tast.jsp
或com/txst.jsp
com/*.jsp
- 匹配目录中的所有.jsp
文件com
com/**/test.jsp
- 匹配路径test.jsp
下的所有文件com
org/springframework/**/*.jsp
- 匹配.jsp
下面的所有文件org/springframework path
org/**/servlet/bla.jsp
- 匹配org/springframework/servlet/bla.jsp
但也org/springframework/testing/servlet/bla.jsp
和org/servlet/bla.jsp
com/{filename:\\w+}.jsp
将匹配com/test.jsp
和的值分配test
给filename
变量
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html
通过@user11153
使用表格来获得更易读的格式,最受好评的答案。
映射使用以下规则匹配 URL:
+-----------------+---------------------------------------------------------+
| Wildcard | Description |
+-----------------+---------------------------------------------------------+
| ? | Matches exactly one character. |
| * | Matches zero or more characters. |
| ** | Matches zero or more 'directories' in a path |
| {spring:[a-z]+} | Matches regExp [a-z]+ as a path variable named "spring" |
+-----------------+---------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
一些例子:
+------------------------------+--------------------------------------------------------+
| Example | Matches: |
+------------------------------+--------------------------------------------------------+
| com/t?st.jsp | com/test.jsp but also com/tast.jsp or com/txst.jsp |
| com/*.jsp | All .jsp files in the com directory |
| com/**/test.jsp | All test.jsp files underneath the com path |
| org/springframework/**/*.jsp | All .jsp files underneath the org/springframework path |
| org/**/servlet/bla.jsp | org/springframework/servlet/bla.jsp |
| also: | org/springframework/testing/servlet/bla.jsp |
| also: | org/servlet/bla.jsp |
| com/{filename:\\w+}.jsp | com/test.jsp & assign value test to filename variable |
+------------------------------+--------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
小智 5
该实用程序使用三个不同的通配符。
+----------+-----------------------------------+
| Wildcard | Description |
+----------+-----------------------------------+
| * | Matches zero or more characters. |
| ? | Matches exactly one character. |
| ** | Matches zero or more directories. |
+----------+-----------------------------------+
Run Code Online (Sandbox Code Playgroud)