4

我在教程(Jersey)中看到有可能传入Long类型的 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)

我用整数测试了它,但它也不起作用......

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 值作为字符串,然后使用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 自动导入上进行中继,并没有看到它是错误的。

4

0 回答 0