Bird
0
0

What does placing @RequestMapping("/api") on a Spring Boot controller class do?

easy📝 Conceptual Q11 of 15
Spring Boot - REST Controllers
What does placing @RequestMapping("/api") on a Spring Boot controller class do?
AAutomatically maps all methods to the root URL <code>/</code>.
BDefines the HTTP method type for all requests in the class.
CSets a base URL path for all request methods inside the class.
DDisables URL mapping for the controller.
Step-by-Step Solution
Solution:
  1. Step 1: Understand class-level @RequestMapping

    When @RequestMapping is placed on a controller class, it sets a base URL path prefix for all methods inside.
  2. Step 2: Effect on method-level mappings

    Each method's path is appended to this base path, organizing URLs under a common root.
  3. Final Answer:

    Sets a base URL path for all request methods inside the class. -> Option C
  4. Quick Check:

    Class-level @RequestMapping sets base path = A [OK]
Quick Trick: Class-level @RequestMapping sets base path prefix [OK]
Common Mistakes:
  • Confusing base path with HTTP method type
  • Thinking it maps all methods to root path
  • Assuming it disables mapping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes