0% found this document useful (1 vote)
28 views4 pages

Full Stack Student Management System

Uploaded by

bb9324985
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
28 views4 pages

Full Stack Student Management System

Uploaded by

bb9324985
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Student Management System - Full Stack Project

Frontend: React

Backend: Java Spring Boot

Project Structure:

student-management/

├── backend/ (Spring Boot)

│ ├── src/

│ └── ...

└── frontend/ (React)

├── src/

└── ...

Backend (Spring Boot):

1. Create Spring Boot App:

$ spring init --dependencies=web,data-jpa,h2 student-backend

2. Code Files:

[Link]

@Entity

public class Student {

@Id

@GeneratedValue

private Long id;


private String name;

private int age;

private String email;

// Getters and Setters

[Link]

public interface StudentRepository extends JpaRepository<Student, Long> {}

[Link]

@RestController

@CrossOrigin(origins = "[Link]

@RequestMapping("/students")

public class StudentController {

@Autowired

private StudentRepository repo;

@GetMapping

public List<Student> getAll() {

return [Link]();

@PostMapping

public Student create(@RequestBody Student student) {

return [Link](student);

}
Frontend (React):

1. Create React App:

$ npx create-react-app student-frontend

$ cd student-frontend

$ npm install axios

2. [Link]

import React, { useEffect, useState } from 'react';

import axios from 'axios';

function App() {

const [students, setStudents] = useState([]);

const [form, setForm] = useState({ name: '', age: '', email: '' });

useEffect(() => {

[Link]("[Link]

.then(res => setStudents([Link]));

}, []);

const handleSubmit = (e) => {

[Link]();

[Link]("[Link] form)

.then(() => [Link]());

};

return (
<div style={{ padding: 20 }}>

<h2>Student Management</h2>

<form onSubmit={handleSubmit}>

<input placeholder="Name" onChange={e => setForm({...form, name:

[Link]})} />

<input placeholder="Age" type="number" onChange={e => setForm({...form,

age: [Link]})} />

<input placeholder="Email" onChange={e => setForm({...form, email:

[Link]})} />

<button type="submit">Add Student</button>

</form>

<ul>

{[Link](s => (

<li key={[Link]}>{[Link]} ({[Link]}) - {[Link]}</li>

))}

</ul>

</div>

);

export default App;

How to Run:

Backend: $ ./mvnw spring-boot:run

Frontend: $ npm start

Common questions

Powered by AI

The React frontend ensures that new student data is immediately reflected in the user interface by reloading the page upon form submission. The handleSubmit function invokes an axios POST request to add a new student, and upon successful completion, it calls window.location.reload() to refresh the page. This reload causes the useEffect hook to re-execute, fetching the updated list of students from the backend, thus causing the UI to reflect the new data .

The Spring Boot backend provides RESTful services that are accessed by the React frontend through HTTP requests. The React frontend uses axios to send GET and POST requests to endpoints exposed by the Spring Boot REST controller. When the frontend initializes, a GET request is sent to fetch all student data, which the backend provides by querying the database using the StudentRepository interface. For adding a student, the frontend sends a POST request with the student data, which the backend handles by saving the data into the database and returning the persisted object. This interaction is facilitated through CORS configuration to allow data exchange between different origins .

Axios is crucial in the React frontend for handling HTTP requests to the backend server. It simplifies the process of performing asynchronous data fetching by returning promises, which can then be used to update the application state. In this application, axios is used within the useEffect hook to make GET requests to the backend for retrieving student information and within the handleSubmit event handler to POST new student data. It supports the application's data handling needs by ensuring that data can be easily fetched and sent, seamlessly integrating the frontend with the backend RESTful services .

The StudentRepository and StudentController classes play crucial roles in the handling of student data in the Spring Boot backend. The StudentRepository interface extends JpaRepository, providing CRUD operations and a mechanism for interacting with the database to perform operations like finding all students or saving a new student entity. The StudentController acts as a RESTful endpoint layer that handles HTTP requests and delegates the data operations to the StudentRepository. It uses the repository to fetch or persist student data based on client requests, thus creating a separation of concerns between data access logic and business logic .

The key components of a Full Stack Student Management System using React and Java Spring Boot include the backend developed with Java Spring Boot, where components include the creation of a Spring Boot application, entity class definition (Student.java), repository interface (StudentRepository.java), and a REST controller (StudentController.java). The frontend is developed using a React app where components include the setup using create-react-app, managing states with React's useState, making HTTP requests with axios in useEffect, handling form submission, and rendering data dynamically from the backend .

CORS policy in this Student Management System is addressed by using the @CrossOrigin annotation in the StudentController class on the backend. This specifies allowed origins, in this case "http://localhost:3000", where the React frontend is served. This setup is necessary to enable the frontend and backend, hosted on different ports, to communicate without triggering the browser's same-origin policy, which normally restricts such interactions for security reasons .

The React frontend application utilizes hooks like useState and useEffect for managing component states and side effects. useState is employed to manage the component's state for the students array and the form data, allowing the component to store and update these states over the component lifecycle. useEffect is used to perform side-effects, specifically to fetch student data from the backend when the component is mounted. The combination of these hooks allows for functional components that manage state without the need for class components, leading to cleaner and more maintainable code .

Key steps in setting up the Spring Boot application for the backend include initializing a Spring Boot project using the command `spring init --dependencies=web,data-jpa,h2 student-backend`, which sets up the project with necessary dependencies such as web, data-jpa, and h2 for web server and data access functionality. This step allows for creating RESTful web services and database interactions. The project structure is defined to allow for efficient development and organization of code files, including entities, repositories, and controllers, which together facilitate handling HTTP requests, managing data, and interacting with databases .

Using Spring Boot and React provides several advantages for developing full-stack applications like the Student Management System. Spring Boot offers a powerful framework for backend development with built-in support for creating RESTful services, managing dependencies, and facilitating data persistence with JPA and databases like H2. It simplifies setup and development while offering scalability. React, on the frontend, provides a robust framework for building rich, interactive UIs with a component-based architecture and state management capabilities. Combined, these technologies enable the development of efficient, scalable, and maintainable full-stack applications with clear separation of frontend and backend responsibilities .

Separation of concerns in this Full Stack Student Management System is demonstrated by the distinct roles assigned to the frontend and backend parts of the application. The backend, developed in Spring Boot, focuses on data representation, business logic, and providing RESTful APIs, encapsulated within structured components such as entities, repositories, and controllers. The frontend, developed in React, is tasked with rendering the user interface, managing user interactions, and asynchronously communicating with the backend. This separation allows for modularity, easier maintenance, and the ability to separately improve or troubleshoot parts of the application without affecting others, leading to scalable and manageable code .

You might also like