0
0
Spring Bootframework~5 mins

@RestController annotation in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @RestController annotation in Spring Boot?
The <code>@RestController</code> annotation marks a class as a controller where every method returns a domain object instead of a view. It combines <code>@Controller</code> and <code>@ResponseBody</code>, making it easier to create RESTful web services.
Click to reveal answer
beginner
How does @RestController differ from @Controller in Spring Boot?
@RestController automatically serializes return objects to JSON or XML and sends them as HTTP responses. @Controller is used for web pages and requires explicit @ResponseBody to return data directly.
Click to reveal answer
beginner
Can you use @RestController on multiple classes in a Spring Boot application?
Yes, you can use <code>@RestController</code> on multiple classes. Each class can handle different REST endpoints, helping organize your API logically.
Click to reveal answer
intermediate
What HTTP response content type does @RestController typically produce?
@RestController typically produces JSON by default, but it can also produce XML or other formats if configured with message converters.
Click to reveal answer
beginner
Why is @RestController considered a convenience annotation?
Because it combines @Controller and @ResponseBody, reducing boilerplate code and making REST API development simpler and cleaner.
Click to reveal answer
What does the @RestController annotation do in Spring Boot?
AMarks a class as a view resolver for HTML pages
BMarks a class as a REST API controller that returns data directly
CDefines a database entity
DConfigures security settings
Which two annotations does @RestController combine?
A<code>@Controller</code> and <code>@ResponseBody</code>
B<code>@Service</code> and <code>@Repository</code>
C<code>@Component</code> and <code>@Entity</code>
D<code>@RequestMapping</code> and <code>@PathVariable</code>
What is the default format of data returned by methods in a @RestController?
AHTML
BCSV
CPlain text
DJSON
If you want to return a web page instead of data, which annotation should you use instead of @RestController?
A<code>@Controller</code>
B<code>@Service</code>
C<code>@Repository</code>
D<code>@Component</code>
Can a Spring Boot application have multiple classes annotated with @RestController?
AOnly if they extend a common base class
BNo, only one is allowed
CYes, to organize different API endpoints
DOnly if they are in different packages
Explain what the @RestController annotation does and why it is useful in Spring Boot applications.
Think about how it simplifies returning data from web endpoints.
You got /4 concepts.
    Describe the difference between @RestController and @Controller in Spring Boot.
    Focus on what each annotation returns to the client.
    You got /4 concepts.