Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anicetkeric/spring-data-specification
Spring Data JPA – Dynamically build queries using JPA Criteria API/Specification
https://github.com/anicetkeric/spring-data-specification
jpa-specification lombok spring-boot spring-data-jpa spring-rest-api
Last synced: about 2 months ago
JSON representation
Spring Data JPA – Dynamically build queries using JPA Criteria API/Specification
- Host: GitHub
- URL: https://github.com/anicetkeric/spring-data-specification
- Owner: anicetkeric
- Created: 2019-07-07T16:41:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-23T17:40:12.000Z (4 months ago)
- Last Synced: 2024-08-23T19:31:18.357Z (4 months ago)
- Topics: jpa-specification, lombok, spring-boot, spring-data-jpa, spring-rest-api
- Language: Java
- Size: 94.7 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spring-data-specification
Spring Data JPA – Dynamically build queries using JPA Criteria API/Specification## Prerequisites
Ensure you have this installed before proceeding further* Spring Boot 3.3.2
* Lombok
* Java 21
* H2 database
* Spring Tool Suite™ (STS) or others### Features
* Order By direction and order By ColumnsName
* Equal/NotEqual/Like/NotLike/In/NotIn/Join support multiple values, Equal/NotEqual support **Null** value.
* Support custom specification.
* Custom Pagination responseDepartment ---> Employee
Create a base Repository class should extends from two super class **JpaRepository** and **JpaSpecificationExecutor**.
```java
@NoRepositoryBean
public interface BaseRepository extends JpaRepository , JpaSpecificationExecutor {}
```Implement specification in Service class
```java
@Service
public class EmployeeServiceImpl implements EmployeeService {
private final EmployeeRepository employeeRepository;
public EmployeeServiceImpl(EmployeeRepository employeeRepo){
this.employeeRepository = employeeRepo;
}@Override
public Page findAllSpecification(Specification specs, Pageable pageable) {
return employeeRepository.findAll(specs, pageable);
}}
```
Endpoint demo
```
GET http://localhost:8080/api/employee/search?page=1&size=10&and=firstName;eq;Steven
GET http://localhost:8080/api/employee/search?page=1&size=10&or=firstName;startwith;K,firstName;like;ir
GET http://localhost:8080/api/employee/search?page=1&size=10&or=firstName;startwith;K,firstName;like;on
```