Bird
0
0

You want to create a controller method that handles both GET and POST requests to "/form". Which is the correct @RequestMapping usage?

hard📝 Application Q8 of 15
Spring Boot - Request and Response Handling
You want to create a controller method that handles both GET and POST requests to "/form". Which is the correct @RequestMapping usage?
A@RequestMapping(path = "/form", method = {RequestMethod.GET, RequestMethod.POST})
B@RequestMapping(path = "/form", method = RequestMethod.GET, RequestMethod.POST)
C@RequestMapping(path = "/form", method = "GET,POST")
D@RequestMapping(path = "/form", method = RequestMethod.GET | RequestMethod.POST)
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to specify multiple HTTP methods

    Spring Boot requires multiple methods to be passed as an array in the method attribute.
  2. Step 2: Evaluate each option's syntax

    @RequestMapping(path = "/form", method = {RequestMethod.GET, RequestMethod.POST}) correctly uses an array: method = {RequestMethod.GET, RequestMethod.POST}.
  3. Final Answer:

    @RequestMapping(path = "/form", method = {RequestMethod.GET, RequestMethod.POST}) -> Option A
  4. Quick Check:

    Multiple methods use array syntax [OK]
Quick Trick: Use curly braces {} to list multiple methods [OK]
Common Mistakes:
  • Listing methods separated by commas without braces
  • Using bitwise OR operator for methods
  • Passing methods as a single string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes