我开发了一个 Spring Web 服务,它将返回一个空响应,但问题是内容类型为 text/palin。我想将内容类型设置为text/xml,已搜索选项但无法找到准确的方法。
这是我的代码:
@Endpoint
public class Service{
@PayloadRoot(namespace = "http://sample.com/webservice", localPart = "sendReport")
@ResponsePayload
public void recieveReport(@RequestPayload SendReport report){
// processing the report response
}
}
有人可以尽快解释一下吗,因为这阻碍了我目前的工作。
最佳答案
如果您使用的是 Spring 3.1,则可以执行此操作
@RequestMapping(value = "/getDealers", method = RequestMethod.GET,
produces = "text/xml; charset=utf-8")
@ResponseBody
public String sendMobileData() {
}
添加 Produce 属性并设置内容类型
还有一种方法
您可以将 response.setContentType("text/xml");
放入您的方法中
public String yourAction(HttpServletResponse response) {
response.setContentType("application/json");
}
关于java - 如何使用spring在响应消息头中将内容类型设置为text/xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29789486/