我在教程(泽西岛)中看到,有可能通过长类型的JAX-RS @PathParam 。
但是当我试图用RESTEasy做到这一点时,我收到了错误:
21:50:32,353 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-15) failed to execute: javax.ws.rs.NotSupportedException: Could not find message body reader for type: long of content type: */*
at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java:52)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73)
我用Integer进行了测试,但它也不起作用......
22:14:45,590 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-18) failed to execute: javax.ws.rs.NotSupportedException: Could not find message body reader for type: class java.lang.Integer of content type: */*
at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java:52)
此外,我试图将此ID值作为String,然后使用 Long.valueOf(String s)或 Long.parseLong(String s)将其转换为Long在这两种情况下我都会收到错误
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:601)
at java.lang.Long.parseLong(Long.java:631)
at pl.salonea.jaxrs.UserAccountResource.getUserAccount(UserAccountResource.java:41)
这是我的网络服务资源方法的代码:
@GET
@Path("/{userId}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public UserAccount getUserAccount(@PathParam("userId") String userId) {
return userAccountFacade.find(Long.parseLong(userId));
}
已解决
我的导入不好导入javax.ws.rs.PathParam; ,但来自网络套接字PathParam ...我只是继续使用IntelliJ自动导入并且没有看到它是错误的。