Bird
0
0

How can you map a controller method to handle any HTTP method for path "/any" using @RequestMapping?

hard📝 Application Q9 of 15
Spring Boot - Request and Response Handling
How can you map a controller method to handle any HTTP method for path "/any" using @RequestMapping?
A@RequestMapping(path = "/any", method = RequestMethod.ALL)
B@RequestMapping(path = "/any", method = {})
C@RequestMapping(path = "/any")
D@RequestMapping(path = "/any", method = null)
Step-by-Step Solution
Solution:
  1. Step 1: Understand default behavior of @RequestMapping

    If no method is specified, the mapping handles all HTTP methods by default.
  2. Step 2: Evaluate options

    @RequestMapping(path = "/any") omits the method attribute, so it handles any HTTP method for "/any".
  3. Final Answer:

    @RequestMapping(path = "/any") -> Option C
  4. Quick Check:

    No method attribute means all HTTP methods handled [OK]
Quick Trick: Omit method attribute to accept all HTTP methods [OK]
Common Mistakes:
  • Using non-existent RequestMethod.ALL
  • Passing empty or null method arrays
  • Thinking method attribute is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes