Spring MVC populate @RequestParam Map

后端 未结 4 1167
轻奢々
轻奢々 2020-12-19 01:58

I have the following method in my Spring MVC @Controller :

@RequestMapping(method = RequestMethod.GET)
public String testUrl(@RequestParam(value=\"test\") Ma         


        
4条回答
  •  天涯浪人
    2020-12-19 02:38

    Spring doesn't have default conversion strategy from multiple parameters with the same name to HashMap. It can, however, convert them easily to List, array or Set.

    @RequestMapping(value = "/testset", method = RequestMethod.GET)
        public String testSet(@RequestParam(value = "test") Set test) {
    
            return "success";
        }
    

    I tested with postman like http://localhost:8080/mappings/testset?test=ABC&test=DEF

    You will see set having data, [ABC, DEF]

提交回复
热议问题