开发者

how to make spring mvc to output xml response?

开发者 https://www.devze.com 2023-02-05 13:57 出处:网络
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!开发者_StackOverflowAssuming that you\'re using Spring 3, then you can h

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消