SPR-6021 - Allow for using MultiValueMap in GET request for mapping multiple request params
This commit is contained in:
parent
465e84eda4
commit
f7ac7a395c
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.web.servlet.mvc.annotation;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
|
@ -1473,6 +1474,22 @@ public class ServletAnnotationControllerTests {
|
|||
assertEquals("templatePath", response.getContentAsString());
|
||||
}
|
||||
|
||||
/*
|
||||
* See SPR-6021
|
||||
*/
|
||||
@Test
|
||||
public void customMapEditor() throws Exception {
|
||||
initServlet(CustomMapEditorController.class);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle");
|
||||
request.addParameter("map", "bar");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
servlet.service(request, response);
|
||||
|
||||
assertEquals("test-{foo=bar}", response.getContentAsString());
|
||||
}
|
||||
|
||||
/*
|
||||
* Controllers
|
||||
*/
|
||||
|
|
@ -2538,5 +2555,36 @@ public class ServletAnnotationControllerTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Controller
|
||||
public static class CustomMapEditorController {
|
||||
|
||||
@InitBinder
|
||||
public void initBinder(WebDataBinder binder) {
|
||||
binder.initBeanPropertyAccess();
|
||||
binder.registerCustomEditor(Map.class, new CustomMapEditor());
|
||||
}
|
||||
|
||||
@RequestMapping("/handle")
|
||||
public void handle(@RequestParam("map") Map map, Writer writer) throws IOException {
|
||||
writer.write("test-" + map);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class CustomMapEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
if (StringUtils.hasText(text)) {
|
||||
setValue(Collections.singletonMap("foo", text));
|
||||
}
|
||||
else {
|
||||
setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ public class HandlerMethodInvoker {
|
|||
throws Exception {
|
||||
|
||||
Class<?> paramType = methodParam.getParameterType();
|
||||
if (Map.class.isAssignableFrom(paramType)) {
|
||||
if (Map.class.isAssignableFrom(paramType) && paramName.length() == 0) {
|
||||
return resolveRequestParamMap((Class<? extends Map>) paramType, webRequest);
|
||||
}
|
||||
if (paramName.length() == 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue