0

In the url of Mapping like

@GetMapping,

is there any difference between

@GetMapping("/users")

and @GetMapping("users")

robert trudel
  • 5,283
  • 17
  • 72
  • 124

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
  • 15,141
  • 6
  • 37
  • 57