https://github.com/kh77/dynamic-query-search
Spring Boot - search specification on controller level
https://github.com/kh77/dynamic-query-search
java jpa-specification spring-boot
Last synced: 10 months ago
JSON representation
Spring Boot - search specification on controller level
- Host: GitHub
- URL: https://github.com/kh77/dynamic-query-search
- Owner: kh77
- Created: 2022-07-19T11:03:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-19T11:03:12.000Z (over 3 years ago)
- Last Synced: 2023-03-06T22:09:08.938Z (almost 3 years ago)
- Topics: java, jpa-specification, spring-boot
- Language: Java
- Homepage:
- Size: 57.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SpringBoot-JPA-DynamicQuery-Specification
Create database with the name of demo
### Sample tables
- Employee
- Department
### How to implement
Step 1. Create Repository interface, extends JpaRepository and JpaSpecificationExecutor.
Step 2. Create Specification class, extends SearchSpecification and override toPredicate method for implement search logic.
#### Demo
- Example searching list of Employee.
GET method
URl : http://localhost:8082/api/employee/list?departmentId=&name=&phone=&departmentName=
- Example searching, sorting and paging for GET method.
GET method
URl : http://localhost:8082/api/employee/page?page=0&sort=desc&sortField=departmentName&firstName=&size=100
- Example searching, sorting and paging for POST method.
POST method
URl : http://localhost:8082/api/employee/search-criteria
Request body :
{
"page" : 0,
"size" : "10",
"sort" : "asc",
"sortField" : "id",
"search" : {
"name" : null,
"phone" : null,
"departmentId" : null,
"departmentName" : null
}
}