蚂蚁路径风格图案

发布于 2024-09-03 09:44:09 字数 69 浏览 5 评论 0原文

蚂蚁路径样式模式的规则是什么。

令人惊讶的是,Ant 网站本身的信息却很少。

What are the rules for Ant path style patterns.

The Ant site itself is surprisingly uninformative.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦中楼上月下 2024-09-10 09:44:09

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

  • ? 匹配一个字符
  • * 匹配零个或多个字符
  • ** 匹配路径中的零个或多个“目录”
  • {spring:[az]+} 匹配正则表达式 [az]+ 作为名为“spring”的路径变量

一些例子:

  • com/t?st.jsp - 匹配 com/test.jsp,但也匹配 com/tast.jspcom/txst.jsp
  • com/*.jsp - 匹配 com 目录中的所有 .jsp 文件
  • com/**/test.jsp - 匹配 com 路径下的所有 test.jsp 文件
  • org/springframework/**/*.jsp - 匹配 org/springframework 路径下的所有 .jsp 文件
  • 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 分配给 <代码>文件名变量

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

Ant-style path patterns matching in :

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 also com/tast.jsp or com/txst.jsp
  • com/*.jsp - matches all .jsp files in the com directory
  • com/**/test.jsp - matches all test.jsp files underneath the com path
  • org/springframework/**/*.jsp - matches all .jsp files underneath the org/springframework path
  • org/**/servlet/bla.jsp - matches org/springframework/servlet/bla.jsp but also org/springframework/testing/servlet/bla.jsp and org/servlet/bla.jsp
  • com/{filename:\\w+}.jsp will match com/test.jsp and assign the value test to the filename variable

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

江湖彼岸 2024-09-10 09:44:09

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

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

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.

黑寡妇 2024-09-10 09:44:09

投票最多的答案,由 @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  |
+------------------------------+--------------------------------------------------------+

Most upvoted answer by @user11153 using tables for a more readable format.


The mapping matches URLs using the following rules:

+-----------------+---------------------------------------------------------+
| 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  |
+------------------------------+--------------------------------------------------------+
骄兵必败 2024-09-10 09:44:09

ANT 样式模式匹配器

通配符

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

+----------+-----------------------------------+
| Wildcard |            Description            |
+----------+-----------------------------------+
| *        | Matches zero or more characters.  |
| ?        | Matches exactly one character.    |
| **       | Matches zero or more directories. |
+----------+-----------------------------------+

ANT Style Pattern Matcher

Wildcards

The utility uses three different wildcards.

+----------+-----------------------------------+
| Wildcard |            Description            |
+----------+-----------------------------------+
| *        | Matches zero or more characters.  |
| ?        | Matches exactly one character.    |
| **       | Matches zero or more directories. |
+----------+-----------------------------------+
泼猴你往哪里跑 2024-09-10 09:44:09

正如@user11153提到的,Spring的 AntPathMatcher 实现并记录了 Ant 风格路径模式匹配的基础知识。

此外,Java 7 的 nio API 通过 FileSystem.getPathMatcher

As @user11153 mentioned, Spring's AntPathMatcher implements and documents the basics of Ant-style path pattern matching.

In addition, Java 7's nio APIs added some built in support for basic pattern matching via FileSystem.getPathMatcher

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文