Using @RequestBody and @ModelAttribute together?

I am trying to get a body POST, and I would like the parameters of my method to communicate with the object.

Is it possible?

My current declaration never hits:

 @RequestMapping(method = RequestMethod.POST)
public void doStuff(@RequestBody byte[] bodyData, @ModelAttribute Form form, Model model ) {

It looks like I am getting this exception:

- 2011-02-25 16:57:30,354 - ERROR - http-8080-3 - org.springframework.web.portle
t.DispatcherPortlet - Could not complete request
java.lang.UnsupportedOperationException: @RequestBody not supported
+5
source share
2 answers

For this to work correctly, you must be sure to use AnnotationMethodHandlerAdapter . This overrides HandlerMethodInvoker createHttpInputMessage (which throws the exception you see). (This is done in a private class.)

I believe you can simply include the following in your * -servlet.xml

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

. @RequestBody @RequestParam . , -.

, Spring 3.0.1. , . @RequestBody @RequestParam. , , HandlerMethodInvoker ( GET) ( ).

(: Scala, Java-)

@RequestMapping(value = "/test", method = RequestMethod.POST)
public String test(
        @RequestBody String body,
        @RequestParam("param1") String parma1,
        Map<Object, Object> model: Map[AnyRef, AnyRef])
{
    model.put("test", test)
    model.put("body", body)

    return "Layout"
}

@PathVariable. , .

+6

, . Spring MVC ( ), JIRA.

AnnotationMethodHandlerAdapter PortletHandlerMethodInvoker , - HandlerMethodInvoker - , HttpMessageConverter-s. null. .

, HandlerMethodInvoker, .. ;)

, Spring MVC HttpMessageConverter-s .

+1

All Articles