我在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
# 1 楼答案
您需要在方法上方添加
@POST
或@GET
标记# 2 楼答案
我遇到了相同的错误消息,但原因与我的情况不同。 你本可以使用:
但我们应该使用:
# 3 楼答案
我相信你是想用
而不是