Browse Source

SPR-6021 - Allow for using MultiValueMap in GET request for mapping multiple request params

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3140 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Arjen Poutsma 16 years ago
parent
commit
da62a2f3df
  1. 48
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java
  2. 2
      org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java

48
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

@ -16,6 +16,7 @@ @@ -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 { @@ -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 { @@ -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);
}
}
}
}

2
org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java

@ -419,7 +419,7 @@ public class HandlerMethodInvoker { @@ -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…
Cancel
Save