how to make spring mvc to output xml response?
Does it has built-in support or I have to do java objects to xml converting by myself? An example would be very helpful. Thanks!开发者_StackOverflow
Assuming that you're using Spring 3, then you can have it automatically marshall the response to XML:
@RequestMapping("/someurl")
public @ResponseBody SomeObject someMethod() {
...
return instanceOfSomeObject;
}
Then in your context you would register an instance of HttpMessageConverter that supports XML, such as MarshallingHttpMessageConverter (with an appropriate Marshaller configured).
精彩评论