Spring 3.0 MVC Data Binding with HTTP PUT
I have a simple Spring 3.0 controller with a PUT request mapping
@Controller
public class FooController {
@RequestMapping(value = "/foo/{id}", method = RequestMethod.PUT)
public @ResponseBody FooView put(@PathVariable String id, @Valid PutFoo putFoo, BindingResult bindingResult) {
inspector.inspect(bindingResult);
开发者_如何转开发 return fooService.update(id, putFoo);
}
}
When I execute a PUT with Foo
parameters in the request body, the PutFoo object is not being populated/binded with that data. If I add HttpServletRequest to the method signature and print the body of the request, sure enough the data is there but PutFoo
is empty.
If I change the request method type to POST and then execute a POST, this all works harmoniously.
For completeness, I'm hitting the endpoint via cURL with
curl -H 'Content-Type: application/x-www-form-urlencoded' -X PUT -F "fooString=foo" http://localhost:8080/foo/9999
Are you sure you are actually sending a http PUT request since you are using conflicting curl parameters. For instance
-F, --form
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388.
source
精彩评论