Java 学习 Ant 路径样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2952196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Learning Ant path style
提问by MDK
Where can I find resources to learn Ant path styleconventions? I've gone to the Ant site itself, but couldn't find any information on path styles.
在哪里可以找到学习Ant 路径样式约定的资源?我已经访问了 Ant 站点本身,但找不到有关路径样式的任何信息。
回答by stacker
I suppose you mean how to use path patterns
我想你的意思是如何使用路径模式
If it is about whether to use slashes or backslashes these will be translated to path-separators on the platform used during execution-time.
如果是关于使用斜杠还是反斜杠,这些将被转换为执行时使用的平台上的路径分隔符。
回答by user11153
Ant-style path patterns matching in spring-framework:
spring-framework 中的Ant 样式路径模式匹配:
The mapping matches URLs using the following rules:
?matches one character*matches zero or more characters**matches zero or more 'directories' in a path{spring:[a-z]+}matches the regexp[a-z]+as a path variable named "spring"Some examples:
com/t?st.jsp- matches com/test.jsp but alsocom/tast.jsporcom/txst.jspcom/*.jsp- matches all.jspfiles in thecomdirectorycom/**/test.jsp- matches alltest.jspfiles underneath thecompathorg/springframework/**/*.jsp- matches all.jspfiles underneath theorg/springframework pathorg/**/servlet/bla.jsp- matchesorg/springframework/servlet/bla.jspbut alsoorg/springframework/testing/servlet/bla.jspandorg/servlet/bla.jspcom/{filename:\\w+}.jspwill matchcom/test.jspand assign the valuetestto thefilenamevariable
映射使用以下规则匹配 URL:
?匹配一个字符*匹配零个或多个字符**匹配路径中的零个或多个“目录”{spring:[a-z]+}匹配正则表达式[a-z]+作为名为“spring”的路径变量一些例子:
com/t?st.jsp- 匹配 com/test.jsp 但也匹配com/tast.jsp或com/txst.jspcom/*.jsp- 匹配目录中的所有.jsp文件comcom/**/test.jsp- 匹配路径test.jsp下的所有文件comorg/springframework/**/*.jsp- 匹配.jsp下面的所有文件org/springframework pathorg/**/servlet/bla.jsp- 匹配org/springframework/servlet/bla.jsp但也org/springframework/testing/servlet/bla.jsp和org/servlet/bla.jspcom/{filename:\\w+}.jsp将匹配com/test.jsp和的值分配test给filename变量
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html
回答by A Jakhar
Wildcards
通配符
The utility uses three different wildcards.
该实用程序使用三种不同的通配符。
+----------+-----------------------------------+
| Wildcard | Description |
+----------+-----------------------------------+
| * | Matches zero or more characters. |
| ? | Matches exactly one character. |
| ** | Matches zero or more directories. |
+----------+-----------------------------------+
回答by romeara
As @user11153 mentioned, Spring's AntPathMatcherimplements and documents the basics of Ant-style path pattern matching.
正如@user11153 提到的,Spring 的AntPathMatcher实现并记录了 Ant 样式路径模式匹配的基础知识。
In addition, Java 7's nio APIs added some built in support for basic pattern matching via FileSystem.getPathMatcher
此外,Java 7 的 nio API 通过FileSystem.getPathMatcher添加了一些对基本模式匹配的内置支持
回答by KostasX
Most upvoted answerby @user11153using tables for a more readable format.
通过@user11153使用表格来获得更易读的格式,最受好评的答案。
The mapping matches URLs using the following rules:
映射使用以下规则匹配 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" |
+-----------------+---------------------------------------------------------+
Some examples:
一些例子:
+------------------------------+--------------------------------------------------------+
| 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 |
+------------------------------+--------------------------------------------------------+

