This project, the "Student Entity Data Mapper Project," is a Spring Boot application that demonstrates mapping and CRUD operations for student and related entities, including Address, Course, Book, Laptop, and Apply (DTO). It provides a set of RESTful API endpoints for managing student records and their associations with these entities. This project serves as a foundation for maintaining student data and related information.
- Framework: Spring Boot
- Language: Java
- Build Tool: Maven
The Student Entity Data Mapper Project uses the following dependencies:
-
Spring Boot Starter Data JPA
- Description: Provides support for JPA (Java Persistence API) and simplifies database access using Spring Data repositories.
- Maven Dependency:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
-
Spring Boot Starter Web
- Description: Provides support for building web applications, including RESTful APIs.
- Maven Dependency:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
-
MySQL Connector/J (Runtime Dependency)
- Description: The MySQL JDBC driver for connecting to MySQL databases.
- Maven Dependency:
<dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency>
-
Project Lombok (Optional)
- Description: A library that simplifies Java code by reducing boilerplate code, such as getters and setters.
- Maven Dependency:
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
-
Spring Boot Starter Test (For Testing)
- Description: Provides support for testing Spring Boot applications.
- Maven Dependency (Test Scope):
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
-
Springdoc OpenAPI (Swagger UI)
- Description: Adds Swagger UI for documenting and testing your API endpoints.
- Maven Dependency:
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.1.0</version> </dependency>
-
Spring Boot Starter Validation
- Description: Includes validation support for request data binding and response data rendering.
- Maven Dependency:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency>
-
Controller Layer
The
StudentController
handles HTTP requests related to students and routes them to theStudentService
.// StudentController.java @RestController @RequestMapping("/students") public class StudentController { // Define student-related endpoints and methods }
-
Service Layer
The
StudentService
contains business logic and interacts with theStudentRepository
to perform CRUD operations on student data.// StudentService.java @Service public class StudentService { // Implement student-related service methods }
-
Repository Layer
The
StudentRepository
manages data access to the student entity using Spring Data JPA.// StudentRepository.java @Repository public interface StudentRepository extends JpaRepository<Student, Long> { // Define custom queries or repository methods if needed }
-
Student Entity
The
Student
entity represents the structure of student data in the database.// Student.java (Student Entity) @Entity public class Student { // Define student attributes, getters, setters, etc. }
Certainly! Here's the continuation of the data flow section including information for the
Course Entity
,Book Entity
,Laptop Entity
, andApply (DTO) Class
:
-
Controller Layer
The
CourseController
handles HTTP requests related to courses and routes them to theCourseService
.// CourseController.java @RestController @RequestMapping("/courses") public class CourseController { // Define course-related endpoints and methods }
-
Service Layer
The
CourseService
contains business logic and interacts with theCourseRepository
to perform CRUD operations on course data.// CourseService.java @Service public class CourseService { // Implement course-related service methods }
-
Repository Layer
The
CourseRepository
manages data access to the course entity using Spring Data JPA.// CourseRepository.java @Repository public interface CourseRepository extends JpaRepository<Course, String> { // Define custom queries or repository methods if needed }
-
Course Entity
The
Course
entity represents the structure of course data in the database.// Course.java (Course Entity) @Entity public class Course { // Define course attributes, getters, setters, etc. }
-
Controller Layer
The
BookController
handles HTTP requests related to books and routes them to theBookService
.// BookController.java @RestController @RequestMapping("/books") public class BookController { // Define book-related endpoints and methods }
-
Service Layer
The
BookService
contains business logic and interacts with theBookRepository
to perform CRUD operations on book data.// BookService.java @Service public class BookService { // Implement book-related service methods }
-
Repository Layer
The
BookRepository
manages data access to the book entity using Spring Data JPA.// BookRepository.java @Repository public interface BookRepository extends JpaRepository<Book, String> { // Define custom queries or repository methods if needed }
-
Book Entity
The
Book
entity represents the structure of book data in the database.// Book.java (Book Entity) @Entity public class Book { // Define book attributes, getters, setters, etc. }
-
Controller Layer
The
LaptopController
handles HTTP requests related to laptops and routes them to theLaptopService
.// LaptopController.java @RestController @RequestMapping("/laptops") public class LaptopController { // Define laptop-related endpoints and methods }
-
Service Layer
The
LaptopService
contains business logic and interacts with theLaptopRepository
to perform CRUD operations on laptop data.// LaptopService.java @Service public class LaptopService { // Implement laptop-related service methods }
-
Repository Layer
The
LaptopRepository
manages data access to the laptop entity using Spring Data JPA.// LaptopRepository.java @Repository public interface LaptopRepository extends JpaRepository<Laptop, String> { // Define custom queries or repository methods if needed }
-
Laptop Entity
The
Laptop
entity represents the structure of laptop data in the database.// Laptop.java (Laptop Entity) @Entity public class Laptop { // Define laptop attributes, getters, setters, etc. }
-
Controller Layer
The
ApplyController
handles HTTP requests related to Apply (DTO) and routes them to theStudentService
for enrollment.// ApplyController.java @RestController @RequestMapping("/apply") public class ApplyController { // Define apply-related endpoints and methods }
-
Student Service Layer
The
StudentService
processes enrollment requests and interacts with theCourseService
for enrollment in a specific course.// StudentService.java @Service public class StudentService { // Implement enrollment-related service methods }
-
Apply (DTO) Class
The
Apply
class represents the Apply (DTO) data structure for enrollment requests.// Apply.java (Apply (DTO) Class) public class Apply { // Define apply attributes, getters, setters, etc. }
The project's database design includes tables for students and related entities, each with specific fields. This design ensures data integrity and organized storage.
Column Name | Data Type | Description |
---|---|---|
id | BIGINT (Primary Key) | Unique identifier for each student |
student_name | VARCHAR(255) | Name of the student |
student_age | INTEGER | Age of the student |
Column Name | Data Type | Description |
---|---|---|
id | BIGINT (Primary Key) | Unique identifier for each address |
street | VARCHAR(255) | Street address of the address |
city | VARCHAR(255) | City where the address is located |
state | VARCHAR(255) | State or region of the address |
zipcode | VARCHAR(20) | Postal code or ZIP code of the address |
student_id | BIGINT (Foreign Key) | Student ID associated with the address |
Column Name | Data Type | Description |
---|---|---|
id | BIGINT (Primary Key) | Unique identifier for each course |
course_name | VARCHAR(255) | Name of the course |
student_id | BIGINT (Foreign Key) | Student ID associated with the course |
Column Name | Data Type | Description |
---|---|---|
id | BIGINT (Primary Key) | Unique identifier for each book |
book_name | VARCHAR(255) | Name of the book |
student_id | BIGINT (Foreign Key) | Student ID associated with the book |
Column Name | Data Type | Description |
---|---|---|
id | BIGINT (Primary Key) | Unique identifier for each laptop |
laptop_name | VARCHAR(255) | Name of the laptop |
student_id | BIGINT (Foreign Key) | Student ID associated with the laptop |
Column Name | Data Type | Description |
---|---|---|
id | BIGINT (Primary Key) | Unique identifier for each application |
student_id | BIGINT (Foreign Key) | Student ID associated with the application |
course_id | BIGINT (Foreign Key) | Course ID associated with the application |
book_id | BIGINT (Foreign Key) | Book ID associated with the application |
laptop_id | BIGINT (Foreign Key) | Laptop ID associated with the application |
The Student
class defines the structure for student data and includes fields such as id
, student_name
, and student_age
.
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String student_name;
private Integer student_age;
// Define relationships with Address, Course, Book, Laptop, and Apply (DTO)
}
The Address
class defines the structure for address data and includes fields such as id
, street
, city
, state
, zipcode
, and a reference to the associated Student
.
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String street;
private String city;
private String state;
private String zipcode;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "student_id")
private Student student;
}
The Course
class defines the structure for course data and includes fields such as id
and course_name
, along with a reference to the associated Student
.
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String course_name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "student_id")
private Student student;
}
The Book
class defines the structure for book data and includes fields such as id
and book_name
, along with a reference to the associated Student
.
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String book_name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "student_id")
private Student student;
}
The Laptop
class defines the structure for laptop data and includes fields such as id
and laptop_name
, along with a reference to the associated Student
.
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Laptop {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String laptop_name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "student_id")
private Student student;
}
The Apply
class represents a Data Transfer Object (DTO) for applying students to courses, books, and laptops. It includes fields such as id
, student_id
, course_id
, book_id
, and laptop_id
.
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Apply {
private Long id;
private Long student_id;
private Long course_id;
private Long book_id;
private Long laptop_id;
}
The project is configured to connect to a MySQL database. Update the application.properties
file with your database configuration:
spring.datasource.url=jdbc:mysql://localhost:3306/YourDatabaseName
spring.datasource.username=YourDatabaseUsername
spring.datasource.password=YourDatabasePassword
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
Make sure your MySQL database is running, and the credentials match those provided in the configuration.
- Start your Spring Boot application.
- Access the API endpoints to create, retrieve, update, and delete student records and related entities.
This project is licensed under the BSD 3-Clause License.
For questions or feedback, please contact Amit Ashok Swain.