Bird
0
0

What is the main purpose of the @RestController annotation in Spring Boot?

easy📝 Conceptual Q11 of 15
Spring Boot - REST Controllers
What is the main purpose of the @RestController annotation in Spring Boot?
ATo create HTML views for web pages
BTo define a service class for business logic
CTo create a controller that returns data directly as JSON or XML
DTo configure database connections
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of @RestController

    @RestController is used to create REST APIs that return data directly, usually in JSON or XML format.
  2. Step 2: Compare with other options

    Creating HTML views is handled by MVC controllers, defining service classes by @Service, and configuring database connections elsewhere in Spring Boot.
  3. Final Answer:

    To create a controller that returns data directly as JSON or XML -> Option C
  4. Quick Check:

    @RestController = returns data directly [OK]
Quick Trick: Remember: @RestController returns data, not HTML pages [OK]
Common Mistakes:
  • Confusing @RestController with @Service
  • Thinking it renders HTML views
  • Assuming it configures database

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes