How to generate Spring WebMVC CRUD API
Asked Answered
P

6

5

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?

Perquisite answered 15/10, 2014 at 9:21 Comment(0)
G
3

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.

Gard answered 15/10, 2014 at 10:59 Comment(1)
This helped, the other parts (and the repository) will be most likely generated with Spring ROO, or if I can help it with Maven subgeneratorsPerquisite
A
3

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

Agamemnon answered 15/10, 2014 at 10:2 Comment(0)
G
3

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.

Gard answered 15/10, 2014 at 10:59 Comment(1)
This helped, the other parts (and the repository) will be most likely generated with Spring ROO, or if I can help it with Maven subgeneratorsPerquisite
E
2

The response is probably in this tutorial :

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

Earthiness answered 5/12, 2014 at 17:38 Comment(0)
R
1

You can take a look at crud-rest-gen project which explains how to use the crud-maven-plugin to generate :

  • the CRUD Rest API
  • the documentation of the API
  • the HTML5/AngularJS CRUD Administration UI
  • the Rest API for retrieving audit information and associated unit tests if you use Hibernate Envers to audit your entities

All you have to provide is the data model containing the JPA entities.

Ranger answered 10/11, 2016 at 18:0 Comment(0)
S
0

Spring-roo (link) have these features, and if you want you can remove spring-roo from your project and remains a java-spring project.

Sample from link :

roo> hint
roo> project --topLevelPackage com.foo
roo> jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY         
roo> entity jpa --class ~.Timer --testAutomatically
roo> field string --fieldName message --notNull
roo> hint web mvc
roo> web mvc setup
roo> web mvc all --package ~.web
roo> selenium test --controller ~.web.TimerController
roo> web gwt setup
roo> web gwt all --proxyPackage ~.client.proxy --requestPackage ~.client.request          
roo> perform tests
roo> quit

As you can see : create the project, setup jpa provider, create Entity, create MVC Controller, the Tests and some GWT setup.

Slaton answered 15/10, 2014 at 9:27 Comment(0)
Q
0

A Yeoman generator for generating Microservices with SpringBoot in Hexagonal Architecture

https://www.npmjs.com/package/generator-springboot-hexagonal

Quaver answered 8/6, 2022 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.