学习蚂蚁路径风格

时间:2010-06-01 18:19:27

标签: java ant path conventions

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

5 个答案:

答案 0 :(得分:109)

中匹配的Ant样式路径模式:

  

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

     
      
  • ?匹配一个字符
  •   
  • *匹配零个或多个字符
  •   
  • **匹配路径中的零个或多个“目录”
  •   
  • {spring:[a-z]+}将正则表达式[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匹配,并将值test分配给filename变量
  •   

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

答案 1 :(得分:38)

我想你的意思是如何使用path patterns

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

答案 2 :(得分:4)

ANT Style Pattern Matcher

通配符

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

+----------+-----------------------------------+
| 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添加了一些对基本模式匹配的内置支持