Bird
0
0

You want to create a controller method that accepts multiple values for the same query parameter "tag" like ?tag=java&tag=spring. Which is the correct way to declare the parameter using @RequestParam?

hard📝 Application Q8 of 15
Spring Boot - REST Controllers
You want to create a controller method that accepts multiple values for the same query parameter "tag" like ?tag=java&tag=spring. Which is the correct way to declare the parameter using @RequestParam?
A@RequestParam List<String> tag
B@RequestParam String tag[]
C@RequestParam Map<String, String> tag
D@RequestParam String tag
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple query parameters

    When multiple values are passed for the same parameter, Spring can bind them to a List or array.
  2. Step 2: Choose correct parameter type

    List is the recommended type for multiple values with @RequestParam.
  3. Final Answer:

    @RequestParam List<String> tag -> Option A
  4. Quick Check:

    Use List for multiple query param values [OK]
Quick Trick: Use List for repeated query params [OK]
Common Mistakes:
  • Using single String for multiple values
  • Using Map instead of List for repeated params
  • Incorrect array syntax in method parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes