Spring Web Initializr
![build][shield-build]
![tests][shield-tests]
![code-coverage-92%][shield-coverage]
![release-2.0.0][shield-release]
![jdk-8][shield-jdk]
![spring-boot-2.0.0.RELEASE][shield-spring]
![MIT licensed][shield-license]
Spring Web Initializr (will be referenced Swi from now on) is a library that helps you easily create Web Apps with Spring Boot.
It was initially developed in order to support the Swip (Spring Web Initializr Plugin)
built for IntelliJ IDEA, but was extended beyond that usage and can be obviously used independently.
TL;DR
<dependency>
<groupId>io.github.orpolyzos</groupId>
<artifactId>spring-web-initializr</artifactId>
<version>2.0.0</version>
</dependency>
Fully working examples can be found at Swi(p) Demo
Table of Contents
Description
Swi is providing implementations for the Create, Read, Update & Delete (CRUD) operations of an Entity (ResourcePersistable)
- CRUD REST API
- exposing directly the ResourcePersistable
- exposing a DTO instead of the ResourcePersistable
- CRUD MVC API (ServerSide Rendering using a compatible Template Engine of your choice)
- exposing directly the ResourcePersistable
- exposing a DTO instead of the ResourcePersistable
Generic Type Parameters
- R stands for the class of the ResourcePersistable, the one annotated with @Entity (e.g. User)
- I stands for the class of the primary key of the ResourcePersistable, the one annotated with @Id (e.g. Long)
- D stands for the class of the DTO that is going to be exposed instead of the ResourcePersistable (e.g. UserDto)
ResourcePersistable\<I>
- Should be implemented by the corresponding Entity (e.g. User)
- There is only a single method to be implemented
I getRpId();
- Should return the primary key field
RpService\<R extends ResourcePersistable\<I>, I extends Serializable, D> extends ResourcePersistableService\<D, I>
- It is responsible for the communication with the corresponding CrudRepository<R,I>
- Should be implemented by the @Service for the corresponding ResourcePersistable (e.g. UserService)
- There are 3 methods to be implemented
CrudRepository<R, I> getRepository();
- Should return the corresponding CrudRepository<R,I> (e.g. UserRepository)
Function<R, D> getEntityToDtoConverter();
- Should provide a way for the ResourcePersistable to be converted to the DTO
Function<D, R> getDtoToEntityConverter();
- Should provide a way for the DTO to be converted to the ResourcePersistable
NoDtoRpService\<R extends ResourcePersistable\<I>, I extends Serializable> extends RpService\<R, I, R>
- NoDtoRpService should be used if we want to expose directly the ResourcePersistable
- Everything from RpService applies to NoDtoRpService, with the difference of 2 already implemented methods
default Function<R, R> getEntityToDtoConverter() { return Function.identity(); }
default Function<R, R> getDtoToEntityConverter() { return Function.identity(); }
RpRestController\<D, I extends Serializable> extends ResourcePersistableRestController\<D, I>
- It is responsible for the communication with the corresponding ResourcePersistableService<R, I>
- Provides a REST API for the CRUD operations of the ResourcePersistable
- Should be implemented by the @RestController for the corresponding ResourcePersistable (e.g. UserRestController)
- There is only a single method to be implemented
ResourcePersistableService<D, I> getService();
- Should return the corresponding ResourcePersistableService<D,I> (e.g. UserService)
RpViewController\<D, I extends Serializable> extends ResourcePersistableViewController\<D, I>
- It is responsible for the communication with the corresponding ResourcePersistableService<R, I, D>
- Provides a MVC API for the CRUD operations of the ResourcePersistable
- Should be implemented by the @Controller for the corresponding ResourcePersistable (e.g. UserController)
- There is only a single method to be implemented
ResourcePersistableService<D, I> getService();
- Should return the corresponding ResourcePersistableService<D,I> (e.g. UserService)
Examples
Contributors
__To contribute to Spring Web Initializr, follow the instructions in our [contributing guide](/contributing.md)__
License
-------
Spring Web Initializr is licensed under the [MIT](/license.md) license.
Copyright © 2019, Orestes Polyzos
[shield-release]: https://img.shields.io/badge/release-2.0.0-blue.svg
[shield-jdk]: https://img.shields.io/badge/jdk-8-blue.svg
[shield-spring]: https://img.shields.io/badge/spring-2.2.1-blue.svg
[shield-license]: https://img.shields.io/badge/license-MIT-blue.svg
[shield-build]: https://github.com/OrPolyzos/spring-web-initializr/workflows/build/badge.svg
[shield-tests]: https://github.com/OrPolyzos/spring-web-initializr/workflows/tests/badge.svg
[shield-coverage]: https://img.shields.io/badge/coverage-92%25-brightgreen.svg