Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double asterisk in a request mapping

What does it mean when double asterisk is present in a request mapping? For instance

@RequestMapping(value = { "/", "/welcome**" }, method =
RequestMethod.GET)  public ModelAndView welcomePage() { ...
like image 621
rozerro Avatar asked Oct 22 '16 05:10

rozerro


2 Answers

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.

like image 168
micaro Avatar answered Nov 12 '22 21:11

micaro


  1. Ant paths

  2. 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.
like image 33
luboskrnac Avatar answered Nov 12 '22 19:11

luboskrnac