[英]Error:param @param is always null
I have a problem with Jersey and Grizzly. 我对泽西岛和灰熊队有疑问。 The problem could be very basic but I am struggling to solve it. 这个问题可能非常基本,但我正在努力解决。 The idea is that I am creating an exercise application that needs to store books. 我的想法是创建一个需要存储书籍的练习应用程序。 Everything seems to be alright but it does not work as expected. 一切似乎都还不错,但不能按预期工作。 Here is the source code: 这是源代码:
@Path("/books")
public class BooksResource
{
private BookDao bookDao= new BookDao();
@GET
@Produces(MediaType.APPLICATION_JSON)
public Collection<Book> getBooks()
{
return (bookDao.getBooks());
}
@Path("/{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Book getBook(@PathParam("id")String id)
{
Book book = bookDao.getBook(id);
return (book);
}
As can be observed, the path /books is working perfectly but the problem is that id is always null and it shouldn't be. 可以观察到,路径/ books正常运行,但是问题在于id始终为null,而不应该为null。 Does anyone know where the problem comes from? 有人知道问题出在哪里吗?
Try removing "/" from the path and it should work. 尝试从路径中删除“ /”,它应该可以工作。
From 从
@Path("/{id}")
To 至
@Path("{id}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.