RESTFUL web服务-媒体类型=application/xml



我目前正在编写一个RESTFUL web服务,并试图向该web服务返回整数。

我在浏览器中遇到500内部服务器错误,当我查看Tomcat日志时,出现了上述错误。

12-Nov-2018 09:47:12.547 SEVERE [http-nio-8080-exec-52] org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo MessageBodyWriter not found for media type=application/xml, type=class java.lang.Integer, genericType=int.

我的代码:

@POST
@Path("/post")
@Produces(MediaType.APPLICATION_XML)
public static int adaptiveAuth(){ 
int message=1;
return message; 
}

如果我用字符串替换函数,它不会给出任何错误。

@POST
@Path("/post")
@Produces(MediaType.APPLICATION_XML)
public static String adaptiveAuth(){ 
String message="POST STRING";
return message; 
}

结果:POST STRING

RESTFUL在MediaType.APPLICATION_XML方面有任何限制吗?

谢谢

Hello尝试使用jax-rs规范中的响应对象

https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Response.html

最好返回响应对象,这样可以灵活地定义状态、正文等

你也可以看到这个主题的现有答案:

从java 中的RESTful web服务方法返回Integer

相关内容

最新更新