Spring MVC 3: Returning XML through @ResponseBody

后端 未结 6 1561
渐次进展
渐次进展 2020-12-04 20:17

Pardon me for posting this noob question, but I have been debugging this problem for quite awhile now. I\'m having a little problem trying to get the response to return the

6条回答
  •  庸人自扰
    2020-12-04 20:40

    Adding produces = MediaType.APPLICATION_XML_VALUE to the RequestMapping and @XmlRootElement to the top of your model object should works

    @RequestMapping(value = "/mylink", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
    public SomeObject doIt(){
        return new SomeObject();
    }
    
    @XmlRootElement
    public class SomeObject {
    
    }
    

提交回复
热议问题