Implementing a RESTful interface for db that I hav

2019-08-26 05:21发布

问题:

I have a database that I have implemented Hibernate integration with. I was wondering what is the best library to use to add a RESTful interface to it?

My plan is to have the user submit their login information. After they are logged into this server I can answer REST calls from them. I will need the ability filter their requests by their user privileges. (In other words, look at their login privileges, and filter out data they shouldn't see and disallow them from changing data they should not be allowed to change).

I figure this can new project that simply takes some code out of my existing codebase. So it can be a standalone server. I am very open to using a lot of new and exciting technologies.

Any suggestions?

I would guess RestEasy, Hibernate, and JBoss server all work well together because they are all Jboss products. Is this correct or is there an easier/better way to do it?

回答1:

Here a couple of good comparisons between JPA and Hibernate: here and here.

Anyway I am using JPA for a simple approach like the one you have described. See here for how to create RESTful web services from db using NetBeans's wizard. and here for an answer on how to give different results depending on the user logged.

The tutorial from NetBeans applies to any web container compliant with Java EE 6 specifications, because it uses JAX-RS library.



回答2:

I think Spring Data Rest is the easiest way to get a REST API for Jpa Entities. You need 3 lines of code to create a repository with CRUD and more !

There are two tutorials at http://appdriver.bitbucket.org/ The first one shows how to create a running web application with JPA, Spring REST, Maven, JQuery and Bootstrap 3 in minutes. May be you should try that than you have a running example and can play around a bit..

The second tutorial shows how to add a new entity and repository. Thats more or less pure Spring REST Data.