Bird
0
0

Given the following Spring Boot class, what will be the output when the controller method is called?

medium📝 component behavior Q4 of 15
Spring Boot - Spring Annotations
Given the following Spring Boot class, what will be the output when the controller method is called?
@Controller
public class HelloController {
    @GetMapping("/hello")
    @ResponseBody
    public String sayHello() {
        return "Hello World";
    }
}
AHello World
B404 Not Found
C500 Internal Server Error
DEmpty response
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Controller and @ResponseBody

    @Controller marks the class as a web controller, and @ResponseBody makes the method return the response body directly.
  2. Step 2: Analyze the method behavior

    The method returns the string "Hello World", so the HTTP response body will contain this text.
  3. Final Answer:

    Hello World -> Option A
  4. Quick Check:

    Controller method returns string = "Hello World" [OK]
Quick Trick: Use @ResponseBody to return plain text from controller methods [OK]
Common Mistakes:
  • Forgetting @ResponseBody causes view lookup
  • Incorrect URL mapping
  • Method returning void

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes