gpt4 book ai didi

Spring:/** 和/* 关于路径的区别

转载 作者:IT老高 更新时间:2023-10-28 13:01:29 25 4
gpt4 key购买 nike

当我们提到路径时,两个星号而不是一个星号有什么区别?

之前我正在调试我的 Spring 3 项目。我试图添加一个 .swf 使用

<spring:url var="flashy" value="/resources/images/flash.swf"/>

我的 web.xml 的 ResourceServlet 看起来像

<servlet-name>Resource Servlet </servlet-name>
<url-pattern>/resources/*</url-pattern>

但不幸的是,我收到了这个错误:

WARN org.springframework.js.resources.ResourceServlet - An attempt to access a protected resource at /images/flash.swf was disallowed.

我觉得这很奇怪,因为我所有的图片都在 images文件夹被访问了,但我的 .swf 怎么被“保护”了?

之后,我决定更改 /resources/*/resources/**它终于奏效了。我的问题是……为什么?

最佳答案

这是在Apache Ant 中使用的路径模式图书馆。 Spring 团队实现并在整个框架中使用它。


回到你的问题。根据 AntPathMatcher 的 Javadoc ,它只有 3 条规则:

  1. ? 匹配一个字符
  2. * 匹配零个或多个字符
  3. ** 匹配路径中的零个或多个“目录”

2022 年更新

在最新的 Spring Framework 版本中有第四条规则:

  1. {spring:[a-z]+} 匹配正则表达式 [a-z]+ 作为名为“spring”的路径变量

查看最新(截至目前)Spring Framework 版本 5 Javadoc 中的详细信息:AntPathMathcer .

关于Spring:/** 和/* 关于路径的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12569308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com