我在这个球衣Java类中做错了什么?

Joh*_*Doe 2 java jax-rs jersey

这是班级: -

 package com.bablo.rest;

 import javax.websocket.server.PathParam;
 import javax.ws.rs.Path;

 @Path("/")
 public class Library {
   @Produces("text/plain") 
   @Path("/books/{name}")
   public String getBook(@PathParam("name") String name){
     System.out.println(name);
      return "My Name is Anthony Goncalves";
  }
}
Run Code Online (Sandbox Code Playgroud)

它给出了这个错误

子资源定位器public java.lang.String com.bablo.rest.Library.geBook(java.lang.String)不能具有实体参数.尝试将参数移动到相应的资源方法.

在索引0处的参数处缺少方法public java.lang.String com.bablo.rest.Library.getBook(java.lang.String)的依赖项

我正在通过浏览器调用这个web服务

     http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo
Run Code Online (Sandbox Code Playgroud)

我也在做卷毛:

     curl -X GET http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo
Run Code Online (Sandbox Code Playgroud)

小智 10

您需要在方法之上@POST@GET之上添加标记.


Sot*_*lis 3

我相信你打算使用

javax.ws.rs.PathParam
Run Code Online (Sandbox Code Playgroud)

而不是

javax.websocket.server.PathParam
Run Code Online (Sandbox Code Playgroud)