Spring Boot REST API for managing students, courses, and grades with JPA, H2 persistence, and query-focused service design.
This project demonstrates a compact Spring Boot API for academic record management. It models students, courses, and grade records, and highlights how JPA relationships, derived queries, JPQL, and native SQL can be used to manage enrollments and fetch academic data in a clean learning-oriented codebase.
- Spring Boot REST API setup
- Spring Data JPA repository pattern
- H2 in-memory database integration
- Many-to-many relationship between students and courses
- Grade tracking with student-course associations
GETendpoint for retrieving a student by IDGETendpoint for listing all studentsPOSTendpoint for saving a studentPOSTendpoint for assigning courses and marks to a student- Derived JPA query for finding students by course name
GETendpoint for retrieving all students enrolled in a given course- JPQL query for retrieving all course names by student ID
GETendpoint for retrieving the list of enrolled course names for a given student- Native query for calculating average grades by student ID
GETendpoint for retrieving a student's average grade
- Java 17
- Spring Boot 3
- Spring Web
- Spring Data JPA
- H2 Database
- Maven
- JUnit 5
college-management-api/
├── CHANGELOG.md
├── README.md
├── pom.xml
├── mvnw
├── mvnw.cmd
└── src/
├── main/
│ ├── java/com/codingninjas/jpaqueries/
│ │ ├── controllers/
│ │ ├── entities/
│ │ ├── repository/
│ │ ├── services/
│ │ └── JpaqueriesApplication.java
│ └── resources/
│ └── application.yml
└── test/
- Open a terminal in the project root.
- Run
mvn test. - Run
mvn spring-boot:run. - Use the API under
http://localhost:8080. - Optional: access the H2 console if needed from the configured Spring Boot app.
Available endpoints:
GET /student/{id}GET /student/{id}/averageGradePOST /studentPOST /student/{id}/courses_marksGET /studentsGET /students/{course}GET /students/{id}/courses
Example request body for creating a student:
{
"name": "Aarav"
}Example request body for assigning courses and marks:
[
{
"course": "Mathematics",
"marks": 91
},
{
"course": "Physics",
"marks": 87
}
]- Demonstrates how to model academic entities with many-to-many and many-to-one JPA relationships
- Shows how service logic can coordinate course creation, grade creation, and student enrollment
- Highlights derived query methods like student lookup by course name for query-driven API design
- Introduces JPQL-based repository queries for targeted projection-style lookups
- Adds native-query based aggregation for average-grade reporting
- Uses H2 in-memory persistence to keep setup lightweight for practice and demos
- Suggested repository description:
Spring Boot REST API for managing students, courses, and grades with JPA, H2 persistence, plus derived-query, JPQL, and native-query academic lookups. - Suggested topics:
java,java-17,spring-boot,spring-data-jpa,h2-database,rest-api,college-management,jpa-queries,jpql,native-query,maven,learning-project,portfolio-project