How to generate Spring WebMVC CRUD API

核能气质少年 提交于 2019-11-30 15:52:29

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.

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!