Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ricall/jpa-validation
Java application demoing JPA persistence, spring-mvc validation, and caching.
https://github.com/ricall/jpa-validation
boot caching flyway java spring validation
Last synced: 5 days ago
JSON representation
Java application demoing JPA persistence, spring-mvc validation, and caching.
- Host: GitHub
- URL: https://github.com/ricall/jpa-validation
- Owner: ricall
- Created: 2021-01-23T10:26:48.000Z (about 4 years ago)
- Default Branch: develop
- Last Pushed: 2021-01-23T19:06:40.000Z (about 4 years ago)
- Last Synced: 2023-11-23T01:39:07.882Z (about 1 year ago)
- Topics: boot, caching, flyway, java, spring, validation
- Language: Java
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jpa-validation
Simple project that demonstrates Spring Boot JSON serialization/deserialization and validation using a simple entity model of `Product` and `ProductType` objects.
Features:
* Spring Boot
* Simple JSON rest endpoints
* Custom JSON serialization/deserialization
* Caching
* JPA + Spring Data Repositories
* Flyway database migration
* Mock MVC testing using jsonPath()
* Jacoco code coverage (with custom exclusions)Example method with request validation.
```java
@PostMapping("/product")
public ResponseEntity addProduct(@Valid @RequestBody Product product) {
return ResponseEntity.ok(service.save(product));
}
```## How to use it
The code can be tested using:
```bash
$ ./gradlew clean check
```To start the application:
```bash
$ ./gradlew bootRun
```The application is available on http://localhost:8080 (You can view the application health on http://localhost:8080/actuator/health)
### Add a product
POST http://localhost:8080/product
```json
{
"name": "Product1",
"type": "X1",
"category": "insurance",
"subCategory": "life insurance",
"roleStart": "2021-01-03T11:00:01",
"roleEnd": null
}
```### Add a product (that will fail validation)
POST http://localhost:8080/product
```json
{
"name": null,
"type": "foo",
"category": null,
"subCategory": null,
"roleStart": null,
"roleEnd": null
}
```### Get a product
GET http://localhost:8080/product/{id}### Get product types
GET http://localhost:8080/productTypes### Update a product
PATCH http://localhost:8080/product/{id}
```json
{
"name": "Product2",
"type": "R3",
"category": "insurance",
"subCategory": "life insurance",
"roleStart": "2021-02-03T11:00:01",
"roleEnd": null
}
```### To flush the cache and force Spring to load entities from the DB
POST http://localhost:8080/cache
```json
RESET
```