是否有JAX-RS类的代码生成器?

时间:2013-12-10 09:53:50

标签: java web-services rest maven java-ee

我有一组实体类。例如BookStudent。现在我想编写提供类似CRUD操作的JAX-RS类。

    @Path("book")
    @Stateless
    public class BookREST{

      @PersistenceContext
      private EntityManager em;

      @Path("save")
      @POST
      public void saveBook(Book b){
        em.persist(b);
      }

      @Path("delete")
      @DELETE
      public void deleteBook(Book b){
        em.remove(b);
      }
      //and so on
    }

    @Path("student")
    @Stateless
    public class StudentREST{

      @PersistenceContext
      private EntityManager em;

      @Path("save")
      @POST
      public void saveStudent(Student s){
        em.persist(s);
      }

      @Path("delete")
      @DELETE
      public void deleteStudent(Student s){
        em.remove(s);
      }
      //and so on
    }

所以最后我有几个JAX-RS类是相同的,除了@Path注释,例如本例@Path("book")@Path("student")

有没有更好的方法来编写这样的类?或者是否有一个工具/ maven插件,我可以传递我的实体类,并为我生成JAX-RS类?

提前致谢。

2 个答案:

答案 0 :(得分:0)

如果您正在使用Eclipse,则可以将EMF框架与TexoTexo/JSON REST Web Services一起使用。这样,您可以创建实体模型并从中生成实体。 Texo Web服务可用于对实体执行CRUD操作。

答案 1 :(得分:0)

如果你问webservices from entities,你可以使用Netbeans

自动创建它们
New File > Webservice > Restful Webservices from entity classes
相关问题