学习蚂蚁路径风格

MDK*_*MDK 87 java ant conventions path

我在哪里可以找到学习Ant路径样式约定的资源?我已经去了Ant站点,但找不到路径样式的任何信息.

use*_*153 129

匹配的Ant风格路径模式:

映射使用以下规则匹配URL:

  • ? 匹配一个字符
  • * 匹配零个或多个字符
  • ** 匹配路径中的零个或多个"目录"
  • {spring:[a-z]+}将regexp [a-z]+与名为"spring"的路径变量相匹配

一些例子:

  • com/t?st.jsp- 匹配com/test.jsp但也com/tast.jspcom/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.jsporg/servlet/bla.jsp
  • com/{filename:\\w+}.jsp将匹配com/test.jsp和的值分配testfilename变量

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html

  • 有没有办法在一个蚂蚁表达式中匹配多个模式?喜欢/ com/*,/ com /./ test.jsp在同一个表达式中? (10认同)

sta*_*ker 39

我想你的意思是如何使用路径模式

如果是关于是否使用斜杠或反斜杠,这些将被转换为执行时使用的平台上的路径分隔符.


Kos*_*asX 6

通过@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

ANT样式匹配器

通配符

该实用程序使用三个不同的通配符。

+----------+-----------------------------------+
| Wildcard |            Description            |
+----------+-----------------------------------+
| *        | Matches zero or more characters.  |
| ?        | Matches exactly one character.    |
| **       | Matches zero or more directories. |
+----------+-----------------------------------+
Run Code Online (Sandbox Code Playgroud)