how to capture multiple parameters using @RequestParam using spring mvc?

前端 未结 6 1445
独厮守ぢ
独厮守ぢ 2020-11-30 01:34

Suppose a hyperlink is clicked and an url is fired with the following parameter list myparam=myValue1&myparam=myValue2&myparam=myValue3 . Now how can I

6条回答
  •  鱼传尺愫
    2020-11-30 02:14

    As of Spring 3.0, you can also use MultiValueMap to achieve this:

    A rudimentary example would be:

    public String someMethod(@RequestParam MultiValueMap params) {
    
        final Iterator>> it = params.entrySet().iterator();
    
        while(it.hasNext()) {
            final String k = it.next().getKey();
            final List values = it.next().getValue();
        }
    
        return "dummy_response";
    
    }
    

提交回复
热议问题