Advertisement
Google Ad Slot: content-top
Spring Boot JPQL
JPQL (Java Persistence Query Language) is a Hibernate-based query language used to retrieve data from the database in Spring Data JPA. It is similar to SQL but operates on entity objects instead of database tables.
Example Entity Class
Let's assume we have a User entity with fields: id, name, email and age.
Table name : user
| id | name | age | |
|---|---|---|---|
| 1 | John | john@gmail.com | 25 |
| 2 | Mike | mike@gmail.com | 35 |
| 3 | Watson | watson@gmail.com | 40 |
| 4 | Kenny | kenny@gmail.com | 45 |
Create JPA Repositories
findAllUsers , findByName , findUsersOlderThan optional queries you don't want to write Jpa write query for you
Create Services
Create Controllers
Advanced JPQL Queries
Testing the REST API with Postman:
Once the application is running, test the endpoints:
Get All Users GET:http://localhost:8080/users
Get User by Name GET:http://localhost:8080/users/{userName}
Get Users Older Than 30 GET:http://localhost:8080/users/older/{age}
Update Email PUT:http://localhost:8080/users/{userID}/email
Delete User DELETE:http://localhost:8080/users/{userID}