In the url of Mapping like
@GetMapping,
is there any difference between
@GetMapping("/users")
and @GetMapping("users")
In the url of Mapping like
@GetMapping,
is there any difference between
@GetMapping("/users")
and @GetMapping("users")
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