This is a simple Spring Boot project which presents Specification Argument Resolver library.
It is an executable jar with embedded H2 db, so just build it with Maven and explore the API. It is also configured to be compiled as native image.
How to build the app:
- jar
- executable -
mvn clean install
- docker image
mvn spring-boot:build-image
- executable -
- native
- executable -
mvn -Pnative native:compile
(should be visible as executable file intarget
directory) - docker image -
mvn -Pnative spring-boot:build-image
It is recommended to run tests against native image to be sure, that the native image contains all the code that is required at runtime:
- executable -
mvn -PnativeTest test
(Native image tested with maven 3.8.7 and GraalVM 22.3.0 for java 17 SDK version)
You will find some samples below:
-
Get all customers:
-
Delete a customer
curl -X DELETE http://localhost:8080/customers/3
it will perform a soft delete, which you can verify by getting all customers again -- the deleted customer will be still there, but with
deleted = true
flag. As you will see in subsequent points, specification-based query methods will filter it out. -
Filter customers (include only not deleted ones) by first name:
-
Filter customers by last name and gender (gender param is optional):
curl http://localhost:8080/customers?lastName=simp curl 'http://localhost:8080/customers?lastName=simp&gender=M'
-
Filter customers by name (either first or last, case insensitive) with paging:
curl 'http://localhost:8080/customers?name=l&page=0&size=2&sort=id'
-
Filter customers by registration date:
curl http://localhost:8080/customers?registeredBefore=2014-01-22 - returns customers registered before given date curl 'http://localhost:8080/customers?registeredAfter=2014-01-01®isteredBefore=2014-01-22' - returns customers registered between given
registeredAfter
andregisteredBefore
params -
Filter customers by name (either first or last, case insensitive) and gender:
-
Filter customers by registration date (customers registered before given date) and name (either first or last, case insensitive). It will return only not deleted customers:
curl 'http://localhost:8080/customers?registeredBefore=2014-01-22&name=simp'