Generating simple crud applications in Spring based off existing database or hibernate configurations?

StackOverflow https://stackoverflow.com/questions/1833724

  •  11-09-2019
  •  | 
  •  

Question

I'm attempting to learn Spring MVC but have been spoiled by Grails. While I am able to get a basic web application working I was wondering if there were any tools that could do some of the work to create a crud application given a database or hibernate data model? The only one I've found so far is http://www.skywayperspectives.org/portal/web/guest/downloads/overview I'm not sure how to take the generated code and convert it to use either maven or ant for it's build process.

Was it helpful?

Solution

I've never tried it but it looks like the Appfuse Maven Plugin (AMP) allows you to do this via Maven. There's a mvn appfuse:gen-model command to reverse engineer from a database and mvn appfuse:gen to create the rest of the scaffold.

I think you have to run these from within a project created with one of the Appfuse Maven archetypes. You can find the quickstart guide here to set that up.

Spring Roo has some nice scaffolding too, but it doesn't have the reverse engineering from the database you're looking for yet. Your persistence objects need to be annotated as @RooEntity objects before you can take advantage of the scaffolding with that framework.

OTHER TIPS

Telosys does this job : http://www.telosys.org

If you have a database it will use it as a model to generate the code (JPA entities, etc)

Standard templates bundles are available to generate a fully operational web application with CRUD screens

Just follow this tutorial: https://sites.google.com/site/telosystutorial/

It will generate a full Web App based on Spring MVC / Spring Data / JPA

Looks like LightAdmin pluggable administration interface for Spring/JPA based applications would be a good choice for you. It has a built-in Java DSL for interface configuration and the only thing you need to do is to download a jar or declare Maven dependency, enable your domain administration through web.xml (point to package containing your JPA entities) and create @Administration configuration class for the entity.

As a result you will have a clean and simple UI for CRUD, filtering, etc.

Here is an example of configuration:

@Administration( Customer.class )
public class CustomerAdministration {

  public static EntityMetadata configuration(EntityMetadataBuilder configurationBuilder ) {
    return configurationBuilder.nameField( "firstname" ).build();
  }

  public static ScreenContext screenContext( ScreenContextBuilder screenContextBuilder ) {
    return screenContextBuilder
           .screenName( "Customers Administration" )
           .menuName( "Customers" ).build();
  }

  public static FieldSet listView( final FieldSetBuilder fragmentBuilder ) {
    return fragmentBuilder
           .field( "firstname" ).caption( "First Name" )
           .field( "lastname" ).caption( "Last Name" ).build();
  }

I have made the same search. Finally had a look at JBoss Seam. Seam appears to have a database schema import and generates the necessary backend and frontend code. Spring Roo seams to be very similar to JBoss Seam, just that Seam is longer there and more mature.

If you want to learn spring MVC with reverse-engineering there is minuteproject track REST-SpringMVC

It 'smart' reverse engineer your db schema, provides

  • JPA2
  • AO w/ spring integration
  • spring MVC and REST integration

Smart reverse-engineering means that your Java entities does not have to follow your DB convention (Ex table T_USER can give Java User class...)

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 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 need to provide is the data model containing the JPA entities.

Many samples are provided, based on the Spring PetClinic data model.

Take a look at Celerio. Here's a link to template Angular 2 + PrimeNG + Spring Boot web application.

Celerio is a code generator tool for data-driven application. It can reverse a database schema and generate advanced CRUD-based applications.

The following screencast shows you what to expect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top