0

I want to learn that is there any difference between @RequestMapping(/home) and @RequestMapping(value="/home")

Thanks,

2 Answers 2

1

As per Spring , both are same. The first one is used when only one url maps to a path.

@RequestMapping("/home") will map the urls: <hostname>:<port>/home to the class or method on which the annotation has been applied.

The second one is used when you have more urls to map to same path. @RequestMapping(value="/home") will do the same as first one. but

@RequestMapping(value = { "/home", "/someotherurl", "/moreUrl" })

will map the following url:

<hostname>:<port>/home <hostname>:<port>/someotherurl <hostname>:<port>/moreUrl to the method or class on top of which the annotation is applied.

Refer: https://dzone.com/articles/using-the-spring-requestmapping-annotation for more details.

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming you mean @RequestMapping("/home") not @RequestMapping(/home) then no, there is no difference.

For annotations with a property named value this is also assumed to be the default and can be passed into the annotation definition without reference to value=. However, this is only valid if you want to define a single property. Otherwise the value= is required.

e.g.:

@RequestMapping(value = "/home", method = RequestMethod.GET)

1 Comment

Sorry yes I meant @RequestMapping("/home"). Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.