Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate Spring WebMVC CRUD API

What I want to do is to create a full Spring WebMVC CRUD API from database tables/Hibernate JPA entities, into an existing Maven Web Project. What I want generate, to be precise:

  • Spring WebMVC controller (mapping&implementation)
  • The JPA entity (if not given) - ofc. using the standard generation built in to most IDEs
  • Spring Data JPA repository
  • Optionally modifying some other files (f.e. adding the entity to existing persistence.xml)

Is there a project for this? What would be the best way to create something like this? What I had thought about:

  • Standalone Java APP
  • Maven subgenerators
  • Eclipse plugin
  • Standard code generation methods (f.e. Acceleo plugin)

What would you suggest?

like image 793
SzaboAdam Avatar asked Oct 15 '14 09:10

SzaboAdam


3 Answers

Partial Answer : If you can generate JPA entities and Spring Data JPA Repositories, you can use Spring Data REST to expose the repositories as a full CRUD REST API.

like image 140
superbob Avatar answered Oct 28 '22 15:10

superbob


Although Spring Roo will generate a CRUD application for you, however the code it generates is outdated. If I where starting a new project, I would definitely stay away from it (at least until a new version is released).

I suggest you take a look at JHipster which is a Yeoman that will generate a CRUD application using some of pretty hot tech (like Spring Boot, AngularJS etc.)

Besides the novelty factor of the generated code, another great feature of the project is that it is extremely active as is evident from the releases

like image 26
geoand Avatar answered Oct 28 '22 17:10

geoand


The response is probably in this tutorial :

https://sites.google.com/site/telosystutorial/springmvc-jpa-springdatajpa

like image 37
lgu Avatar answered Oct 28 '22 15:10

lgu