Reputation: 86747
I want to create a backend application maintaining entries in a database and offer them via REST
. Therefore I want to use spring
.
Is there any tool that could autogenerate the CRUD and service classes for this purpose? Because these kind of operations are always the same or at least similar for each entity.
Example:
@Entity
class MyEntity {
//some properties to be explosed to REST, some not
}
@Controller
public class ServiceController {
//fetch DB entries and offer them to the rest facade
}
@Service
public class RestService {
//expose GET functions via REST/JSON/XML
//@RequestMapping(..GET..)
}
Or are there other possibilities to simplify the initial development?
Upvotes: 3
Views: 671
Reputation: 414
As pointed out in comments, Spring Data Rest does exactly that.
You'll get CRUD operations, filtering capabilities Hypermedia support, sorting, pagination... all available through REST.
Spring data rest relies on Spring Data, so no matter what persistence technology you are using it will work, as long as Spring Data supports it. Also, it uses Spring HATEOAS for all the Hypermedia stuff.
It's quite straight forward to get started, have a look into the official documentation.
As a personal opinion it's a lovely project to speed up RESTful apis, you typically end up having the need to shadow some methods to get finer control over some specific situations, but still it definitely worth it.
Upvotes: 1