How to Pass Primitive Array to Spring MVC Controller
Receive from Request URL Query String
Integer Array
Frontend Pass with HTTP request
- url?ids=1,2,3
- url?ids=1&ids=2&ids=3
Backend receive in controller methods
Integer[] ids
@RequestParam Integer[] ids
@RequestParam List<Integer> ids
String Array
Frontend Pass with HTTP request
- url?ids=a,b,c
- url?ids=a&ids=b&ids=c
Backend receive in controller methods
String[] ids
@RequestParam String[] ids
@RequestParam List<String> ids
Receive from Form Data
Integer Array
Frontend Pass with HTTP request
- ids=1,2,3
- ids=1, ids=2, ids=3
Backend receive in controller methods
Integer[] ids
@RequestParam Integer[] ids
@RequestParam List<Integer> ids
String Array
Frontend Pass with HTTP request
- ids=a,b,c
- ids=a, ids=b, ids=c
Backend receive in controller methods
String[] ids
@RequestParam String[] ids
@RequestParam List<String> ids
Receive from request body JSON
Integer Array
Frontend Pass with HTTP request
- [1,2,3]
Backend receive in controller methods
@RequestBody Integer[] ids
@RequestBody List<Integer> ids
String Array
Frontend Pass with HTTP request
- [“a”,”b”,”c”]
Backend receive in controller methods
@RequestBody String[] ids
@RequestBody List<String> ids