Skip to content

Commit f3dae0c

Browse files
committed
Mention AntPathMatcher regexp support
This commit documents the regexp support in `AntPathMatcher` when matching for URL patterns. This support is also mentioned in places where developers can register patterns for ViewControllers or resource handlers. Issue: SPR-14652 Cherry-picked from: a8ba065
1 parent dc2cafc commit f3dae0c

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* <li>{@code ?} matches one character</li>
3636
* <li>{@code *} matches zero or more characters</li>
3737
* <li>{@code **} matches zero or more <em>directories</em> in a path</li>
38+
* <li>{@code {spring:[a-z]+}} matches the regexp {@code [a-z]+} as a path variable named "spring"</li>
3839
* </ul>
3940
*
4041
* <h3>Examples</h3>
@@ -50,6 +51,8 @@
5051
* <li><code>org/&#42;&#42;/servlet/bla.jsp</code> &mdash; matches
5152
* {@code org/springframework/servlet/bla.jsp} but also
5253
* {@code org/springframework/testing/servlet/bla.jsp} and {@code org/servlet/bla.jsp}</li>
54+
* <li>{@code com/{filename:\\w+}.jsp} will match {@code com/test.jsp} and assign the value {@code test}
55+
* to the {@code filename} variable</li>
5356
* </ul>
5457
*
5558
* <p><strong>Note:</strong> a pattern and a path must both be absolute or must

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletCon
9292
* Add a resource handler for serving static resources based on the specified URL path
9393
* patterns. The handler will be invoked for every incoming request that matches to
9494
* one of the specified path patterns.
95+
* <p>Patterns like {@code "/static/**"} or {@code "/css/{filename:\\w+\\.css}"}
96+
* are allowed. See {@link org.springframework.util.AntPathMatcher} for more details on the
97+
* syntax.
9598
* @return A {@link ResourceHandlerRegistration} to use to further configure the
9699
* registered resource handler
97100
*/

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class ViewControllerRegistry {
4949
/**
5050
* Map a view controller to the given URL path (or pattern) in order to render
5151
* a response with a pre-configured status code and view.
52+
* <p>Patterns like {@code "/admin/**"} or {@code "/articles/{articlename:\\w+}"}
53+
* are allowed. See {@link org.springframework.util.AntPathMatcher} for more details on the
54+
* syntax.
5255
*/
5356
public ViewControllerRegistration addViewController(String urlPath) {
5457
ViewControllerRegistration registration = new ViewControllerRegistration(urlPath);

0 commit comments

Comments
 (0)