简体   繁体   中英

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. Does anyone know where the problem comes from?

Try removing "/" from the path and it should work.

From

@Path("/{id}")

To

@Path("{id}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM