2V0-72.22PSE · Question #87
Which two statements are true about the @RequestMapping annotation? (Choose two.)
The correct answer is D. It can be used as an alternative to @GetMapping or @PutMapping using method attribute. E. It is an annotation for mapping web requests to controller methods. @RequestMapping is Spring MVC's foundational web-request mapping annotation, making E straightforwardly true - it maps incoming HTTP requests to controller handler methods (and classes). D is true because @GetMapping and @PutMapping are simply composed shortcuts…
Question
Which two statements are true about the @RequestMapping annotation? (Choose two.)
Options
- AIt can only be used to annotate a method inside an @Controller annotated class.
- BIt may be used to map a controller method to a view.
- CIt does not support HEAD method.
- DIt can be used as an alternative to @GetMapping or @PutMapping using method attribute.
- EIt is an annotation for mapping web requests to controller methods.
How the community answered
(46 responses)- A7% (3)
- B2% (1)
- C2% (1)
- D89% (41)
Explanation
@RequestMapping is Spring MVC's foundational web-request mapping annotation, making E straightforwardly true - it maps incoming HTTP requests to controller handler methods (and classes). D is true because @GetMapping and @PutMapping are simply composed shortcuts; @RequestMapping(method = RequestMethod.GET) is exactly equivalent to @GetMapping, so @RequestMapping can substitute for either by specifying the method attribute.
Why the distractors are wrong:
- A -
@RequestMappingcan annotate both classes and methods, and works on@RestControlleras well as@Controller(and even plain@Componentbeans in some configurations), so "only inside@Controller" is too restrictive. - B - The annotation maps requests to handler methods, not to views. View resolution is a separate concern handled by the return value and a
ViewResolver, not by@RequestMappingitself. - C -
@RequestMappingfully supportsRequestMethod.HEADvia itsmethodattribute, so this is factually false.
Memory tip: Think of @RequestMapping as the parent/generic version, and @GetMapping, @PostMapping, @PutMapping, etc. as convenient child shortcuts. Any shortcut annotation can be replaced by @RequestMapping + the corresponding method = RequestMethod.XXX - that relationship is exactly what option D tests.
Topics
Community Discussion
No community discussion yet for this question.