有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

我在jersey Java课程中做错了什么?

以下是课程:

 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";
  }
}

这是错误的

子资源定位器,公共java。lang.String.com。巴布罗。休息图书馆geBook(java.lang.String)不能有实体参数。尝试将参数移动到相应的资源方法

缺少公共java方法的依赖项。lang.String.com。巴布罗。休息图书馆索引0处参数处的getBook(java.lang.String)

我是这样通过浏览器调用这个Web服务的

     http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo

我也在做卷发:

     curl -X GET http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo

共 (3) 个答案

  1. # 1 楼答案

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

  2. # 2 楼答案

    我遇到了相同的错误消息,但原因与我的情况不同。 你本可以使用:

    @Post (oracle.jdbc.proxy.annotation)
    

    但我们应该使用:

    @POST (javax.ws.rs.POST)
    
  3. # 3 楼答案

    我相信你是想用

    javax.ws.rs.PathParam
    

    而不是

    javax.websocket.server.PathParam