React + Spring Boot Full Stack Example
Project Overview
Goal: Display a list of users fetched from backend
Frontend: React (calls API)
Backend: Spring Boot (serves JSON)
Backend: Spring Boot (Java)
1. [Link] (Entity Class)
public class User {
private int id;
private String name;
public User(int id, String name) {
[Link] = id;
[Link] = name;
public int getId() { return id; }
public String getName() { return name; }
2. [Link]
@RestController
@CrossOrigin(origins = "[Link]
public class UserController {
@GetMapping("/users")
public List<User> getUsers() {
return [Link](
new User(1, "Bala"),
new User(2, "Ajay"),
React + Spring Boot Full Stack Example
new User(3, "Divya")
);
Frontend: React
1. React Component ([Link])
import React, { useEffect, useState } from "react";
function App() {
const [users, setUsers] = useState([]);
useEffect(() => {
fetch("[Link]
.then((res) => [Link]())
.then((data) => setUsers(data));
}, []);
return (
<div>
<h2>User List</h2>
<ul>
{[Link]((user) => (
<li key={[Link]}>{[Link]}</li>
))}
</ul>
</div>
);
}
React + Spring Boot Full Stack Example
export default App;
Result
Spring Boot sends user data (JSON)
React fetches it and displays on browser