What does it mean when double asterisk is present in a request mapping? For instance
@RequestMapping(value = { "/", "/welcome**" }, method =
RequestMethod.GET) public ModelAndView welcomePage() { ...
Universally speaking asterisks (in wildcard role) mean
/welcome*
: anything in THIS folder or URL section, that starts with "/welcome"
and ends before next "/"
like /welcomePage
.
/welcome**
: any URL, that starts with "/welcome"
including sub-folders and sub-sections of URL pattern like /welcome/section2/section3/
or /welcomePage/index
.
/welcome/*
: any file, folder or section inside welcome (before next "/"
) like /welcome/index
.
/welcome/**
: any files, folders, sections, sub-folders or sub-sections inside welcome.
In other words one asterisk * ends before next "/"
, two asterisks ** have no limits.
Ant paths
URL mapping ordering. From Spring Docs:
When a URL matches multiple patterns, a sort is used to find the most specific match.
A pattern with a lower count of URI variables and wild cards is considered more specific. For example /hotels/{hotel}/* has 1 URI variable and 1 wild card and is considered more specific than /hotels/{hotel}/** which as 1 URI variable and 2 wild cards
...
There are also some additional special rules:
- The default mapping pattern /** is less specific than any other pattern. For example /api/{a}/{b}/{c} is more specific.
- A prefix pattern such as /public/** is less specific than any other pattern that doesn’t contain double wildcards. For example /public/path3/{a}/{b}/{c} is more specific.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With