在哪里可以找到学习 Ant路径样式约定的资源?我已经去了Ant网站,但找不到路径样式的任何信息。
答案 0 :(得分:109)
spring-framework中匹配的Ant样式路径模式:
映射使用以下规则匹配URL:
?
匹配一个字符*
匹配零个或多个字符**
匹配路径中的零个或多个“目录”{spring:[a-z]+}
将正则表达式[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
答案 1 :(得分:38)
我想你的意思是如何使用path patterns
如果是关于是否使用斜杠或反斜杠,这些将被转换为执行时使用的平台上的路径分隔符。
答案 2 :(得分:4)
该实用程序使用三种不同的通配符。
+----------+-----------------------------------+
| Wildcard | Description |
+----------+-----------------------------------+
| * | Matches zero or more characters. |
| ? | Matches exactly one character. |
| ** | Matches zero or more directories. |
+----------+-----------------------------------+
答案 3 :(得分:1)
由@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" |
+-----------------+---------------------------------------------------------+
一些例子:
+------------------------------+--------------------------------------------------------+
| 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 |
+------------------------------+--------------------------------------------------------+
答案 4 :(得分:0)
正如@ user11153所述,Spring的AntPathMatcher实现并记录了Ant样式路径模式匹配的基础。
此外,Java 7的nio API通过FileSystem.getPathMatcher添加了一些对基本模式匹配的内置支持