0
我想了解REST和JAX-RS/JAXB,我有許多對多的關係,包括圖書館和書籍。我想對圖書館擁有的圖書進行GET-POST-PUT-DELETE操作,所以GET的url是「libraries/{library_id}/books/{book_id}」 我已經用這種方式實現了:JAX-RS中擁有的資源
@Stateless
@Path("libraries")
public class LibraryFacadeREST extends AbstractFacade<Library> {
...
@Path("{library_id}/booksFacade/")
public BookFacadeREST getBookFacade() {
return bookFacadeREST;
}
...
}
@Stateless
@Path("books")
public class BookFacadeREST extends AbstractFacade<Book> {
...
@GET
@Path("{id}")
@Produces({"application/xml", "application/json"})
public Book find(@PathParam("id") Long id, @PathParam("library_id") long libraryId) {
Book book = super.find(id);
if (libraryId != -1) {
Library library = em.find(Library.class, libraryId);
if (book.getLibraries().contains(library)) {
return book;
} else {
return null;
}
}
return null;
}
...
}
但我不喜歡它,它很糟糕,是否有更好的方法來管理jaxrs中的資源?
是的,我在想同樣的事情。通過這種方式,類更具可讀性。 – Antonio 2012-02-22 13:04:04