nerdexam
Broadcom-VMware

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…

Core Spring

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)
  • A
    7% (3)
  • B
    2% (1)
  • C
    2% (1)
  • D
    89% (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 - @RequestMapping can annotate both classes and methods, and works on @RestController as well as @Controller (and even plain @Component beans 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 @RequestMapping itself.
  • C - @RequestMapping fully supports RequestMethod.HEAD via its method attribute, 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

#@RequestMapping#HTTP Method Mapping#Spring MVC#Controller Methods

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice