我目前正在編寫一個 RESTFUL Web 服務(wù)并嘗試將整數(shù)返回到 Web 服務(wù)。我從瀏覽器中遇到 500 Internal Server Error,當(dāng)我檢查 Tomcat 日志時,發(fā)生了上述錯誤。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; }如果我用字符串替換函數(shù),它不會給出任何錯誤。@POST @Path("/post") @Produces(MediaType.APPLICATION_XML) public static String adaptiveAuth(){ String message="POST STRING"; return message; }結(jié)果:發(fā)布字符串RESTFUL 關(guān)于 MediaType.APPLICATION_XML 是否有任何限制?謝謝
1 回答

侃侃無極
TA貢獻(xiàn)2051條經(jīng)驗 獲得超10個贊
您好嘗試使用 jax-rs 規(guī)范中的 Response 對象
https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Response.html
最好返回響應(yīng)對象,它可以讓您靈活地定義狀態(tài)、正文等。
添加回答
舉報
0/150
提交
取消