This project is a web application built using React for the frontend and Spring Boot for the backend. It uses Maven for dependency management, and Yarn/NPM for managing JavaScript dependencies. The application demonstrates how data is fetched from a database, processed by services, and presented on a webpage.
- Java 11 or higher
- Maven
- Node.js and npm or Yarn
- IDE (IntelliJ IDEA recommended)
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Navigate to the backend directory:
cd backend
-
Build the project using Maven:
mvn clean install
-
Run the Spring Boot application:
mvn spring-boot:run
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies using Yarn or npm:
npm install
-
Start the development server:
npm start
-
Database: The application uses a relational database to store data. The database schema is defined using JPA (Java Persistence API) entities.
-
Repository Layer: JPA repositories are used to interact with the database. These repositories provide CRUD operations and custom queries.
-
Service Layer: Services contain business logic and interact with repositories to fetch and process data.
-
Controller Layer: REST controllers expose endpoints for the frontend to consume. They use services to get data and return it as JSON.
-
Frontend: React components fetch data from the backend using HTTP requests (e.g., Axios or Fetch API) and render it on the webpage.
Services in the Spring Boot application are responsible for handling business logic. They interact with repositories to fetch data and perform operations. Below is an example of a service class:
@Service
public class ExampleService {
@Autowired
private ExampleRepository exampleRepository;
public List<ExampleEntity> getAllExamples() {
return exampleRepository.findAll();
}
public ExampleEntity getExampleById(Long id) {
return exampleRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Example not found"));
}
public ExampleEntity createExample(ExampleEntity example) {
return exampleRepository.save(example);
}
public void deleteExample(Long id) {
exampleRepository.deleteById(id);
}
}