Bird
0
0

What is wrong with this mapping?

medium📝 Debug Q14 of 15
Spring Boot - Request and Response Handling
What is wrong with this mapping?
@RequestMapping(path = "/data", method = "POST")
public String saveData() {
    return "Saved";
}
AThe method attribute should use RequestMethod.POST, not a string.
BThe path attribute cannot be used with @RequestMapping.
CThe method must return void, not String.
DThe method name must be saveDataPost, not saveData.
Step-by-Step Solution
Solution:
  1. Step 1: Check method attribute type

    The method attribute expects a RequestMethod enum value, not a string.
  2. Step 2: Identify correct usage

    Using method = "POST" is invalid; it should be method = RequestMethod.POST.
  3. Final Answer:

    The method attribute should use RequestMethod.POST, not a string. -> Option A
  4. Quick Check:

    method attribute needs RequestMethod enum [OK]
Quick Trick: Use RequestMethod.POST enum, not string "POST" [OK]
Common Mistakes:
  • Passing HTTP method as string instead of enum
  • Thinking path attribute is invalid
  • Assuming return type or method name causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes