On Apr 21, 2008, at 12:57 PM, Martin Probst wrote:
>
> in the next chapter of my adventures with Jersey and JSR311, I'm
> trying to model my resources into persistent entities and non-
> persistent classes representing root collections of those entities.
> That is, if I have a "book" resource, I'd like to have these two
> classes:
>
> @Path("/books/")
> class Books {
> List<Book> getBooks() { ... }
> @Path(" ??? ")
> Book getBook() { ... }
> }
>
> Ideally, I'd like my book collection to reside on "/books/" and my
> single books to reside on "/book/12". Is that possible with JSR311
> annotations? Can I refer to a parent path e.g. by "../book/
> {bookId}"? Or is this better served by a different implementation
> pattern?
>
@Path on a method is relative to the @Path of the class so you can't
do what you want with a single class. Instead you can write:
@Path("books")
class BooksResource {
List<Book> getBooks() {...}
}
@Path("book/{id}")
class BookResource {
Book getBook{_at_PathParam("id") String bookId) {...}
}
HTH,
Marc.
> Sorry if I'm spamming the list, I promise to write responses into
> FAQ entries, once I understand how to do this :-)
>
> Regards,
> Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.