Map parameter as GET param in Spring REST controller

alexanoid picture alexanoid · Nov 7, 2015 · Viewed 9.5k times · Source

How I can pass a Map parameter as a GET param in url to Spring REST controller ?

Answer

prash picture prash · Feb 25, 2019

It’s possible to bind all request parameters in a Map just by adding a Map object after the annotation:

@RequestMapping("/demo")
public String example(@RequestParam Map<String, String> map){
    String apple = map.get("APPLE");//apple
    String banana = map.get("BANANA");//banana

    return apple + banana;
}

Request

/demo?APPLE=apple&BANANA=banana

Source -- https://reversecoding.net/spring-mvc-requestparam-binding-request-parameters/