0

In the url of Mapping like

@GetMapping,

is there any difference between

@GetMapping("/users")

and @GetMapping("users")

robert trudel
  • 4,469
  • 15
  • 61
  • 104

1 Answers1

1

Actually NO.

If the path does not start with an / then Spring (DefaultAnnotationHandlerMapping) will add it.

See the below method String[] determineUrlsForHandler(String beanName) of Class DefaultAnnotationHandlerMapping.

String[] methodLevelPatterns = determineUrlsForHandlerMethods(handlerType, true);
for (String typeLevelPattern : typeLevelPatterns) {
    if (!typeLevelPattern.startsWith("/")) {
            typeLevelPattern = "/" + typeLevelPattern;
    }

See this use-or-not-leading-slash-in-value-for-requestmapping

Alien
  • 13,439
  • 5
  • 35
  • 53