I have a web request like
/path?param=value1¶m=value2
which maps to a List<String>
param on the Controller side.
The important aspect to note is that value1 and value2 can have a comma(,) in their values.
I see 2 different behaviors with spring request parameter mapping.
Case 1. /path?param=part1%2Cpart2 (url encoded comma)
Spring request parameter maps this to a List of size 2 with part1 and part2 as the elements, but HttpServletRequest.getParameterValues("param")
is correctly assigned to an array of size 1 with value=part1,part2
Case 2. /path?param=part1%2Cpart2¶m=part3%2Cpart4
In this case Spring correctly maps this to a list of 2 values, and so does the HttpServletRequest parameter.
I guess Spring is supporting mapping List
parameter with both csv values and repeating the parameter. Is there a way to tell Spring to use a particular mapping method?
I'm using spring-mvc 3.2.13
@Controller
public class MyController {
@RequestMapping(value = "/mymethod", method = RequestMethod.POST)
public @ResponseBody Boolean method(MyRequest myReq, HttpServletRequest request) {
}
}
public class MyRequest {
List<String> param;
}
@Controller
handle multiple keys in GET params. Post your@Controller
code, then we have more information to work from. - Jan Vladimir Mostert