This is a full-stack web application built using:
- Frontend: React.js with Bootstrap
- Backend: Spring Boot (Java)
- Database: MySQL
The application supports full CRUD operations (Create, Read, Update, Delete) for users, with proper exception handling and RESTful architecture.
fullstack-application/
│
├── backend/
│ ├── controller/ # REST controllers
│ ├── model/ # User entity
│ ├── repository/ # UserRepository (extends JpaRepository)
│ ├── exception/ # Custom exceptions and global handler
│ └── application.properties
│
├── frontend/
│ ├── components/
│ │ ├── layout/ # Navbar component
│ │ └── pages/
│ │ ├── Home.js
│ │ ├── AddUser.js
│ │ ├── EditUser.js
│ │ └── ViewUser.js
│ └── App.js
- Spring Web
- Spring Boot DevTools
- Lombok
- Spring Data JPA
- MySQL Driver
- Create a new Spring Boot project.
- Create the
Usermodel class with fields:id,name,username,email. - Create a MySQL database and configure
application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/yourdbname
spring.datasource.username=yourusername
spring.datasource.password=yourpassword
spring.jpa.hibernate.ddl-auto=update-
Create the
UserRepositoryextendingJpaRepository<User, Long>. -
Create
UserControllerwith endpoints:POST /addUser– add new userGET /user/allUsers– get all usersGET /user/{id}– get user by IDPUT /user/{id}– update userDELETE /user/{id}– delete user
-
Add
@CrossOrigin(origins = "http://localhost:3000")to allow React access.
- Create
UserNotFoundExceptionextendingRuntimeException. - Create
UserNotFoundAdviceclass with:
@ControllerAdvice
public class UserNotFoundAdvice {
@ResponseBody
@ExceptionHandler(UserNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public Map<String, String> handleException(UserNotFoundException ex) {
Map<String, String> error = new HashMap<>();
error.put("errorMessage", ex.getMessage());
return error;
}
}- Create app:
npx create-react-app frontend
cd frontend- Install dependencies:
npm install axios react-router-dom bootstrap- Import Bootstrap in
index.js:
import 'bootstrap/dist/css/bootstrap.min.css';components/
│
├── layout/
│ └── Navbar.js
├── pages/
│ ├── Home.js
│ ├── AddUser.js
│ ├── EditUser.js
│ └── ViewUser.js
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import Navbar from './components/layout/Navbar';
import Home from './components/pages/Home';
import AddUser from './components/pages/AddUser';
import EditUser from './components/pages/EditUser';
import ViewUser from './components/pages/ViewUser';
function App() {
return (
<Router>
<Navbar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/addUser" element={<AddUser />} />
<Route path="/editUser/:id" element={<EditUser />} />
<Route path="/viewUser/:id" element={<ViewUser />} />
</Routes>
</Router>
);
}
export default App;- Fetch all users using
axios.get()on load (useEffect) - Display in a Bootstrap table
- Buttons: View, Edit, Delete
- Delete uses
axios.deleteand refreshes data after removal
- Controlled form with
name,username,email axios.postto add user- On success, redirect to Home
- Uses
useParamsto get ID from URL - Fetch user by ID on mount
- On submit:
axios.putwith updated data - Redirect to Home after update
- Shows selected user's data
- Fetch using
axios.get(/user/{id})
- Use
alert(response.data)ortoastfor user feedback - Use
navigate("/")after add/edit for redirection - Handle errors gracefully using try/catch and alerts
- Use
useEffectdependency arrays correctly to avoid warnings
This project is a clean and simple example of how to build a full-stack CRUD web app using modern tools. It uses:
- React for frontend UI
- Spring Boot for RESTful backend
- MySQL for persistent data
- Bootstrap for styling
- Axios for API communication
Feel free to fork this repo, improve it, or use it as a boilerplate for your own full-stack apps!