Spring Boot 4 · Controllers and beans
Write a REST controller
Return objects from handler methods as JSON.
@RestController
@RequestMapping("/api/users")
public class UserController {
@GetMapping("/{id}")
public User get(@PathVariable Long id) {
return service.find(id);
}
}
Official Spring Boot 4 documentation
More controllers and beans commands
All controllers and beans commands · Spring Boot 4 cheatsheet