Fetching the code, complexity notes and tags. Just a moment.
This snippet demonstrates how to create a simple REST API using Spring Boot. It showcases the use of the @RestController annotation, request mapping, path variables, and HTTP GET endpoints. REST Controllers are the foundation of modern backend development and are widely used for building scalable web services and APIs. This is one of the most frequently asked Spring Boot interview topics for Java backend developers.
Category
springboot
Complexity
Time: O(1) Space: O(1)
Language
Java
Status
Tags
Related Concepts
Published
Last Updated
Production-ready Java implementation for quick revision, interview preparation, and real-world development.
Solution.java
1import org.springframework.web.bind.annotation.GetMapping;2import org.springframework.web.bind.annotation.PathVariable;3import org.springframework.web.bind.annotation.RequestMapping;4import org.springframework.web.bind.annotation.RestController;5 6@RestController7@RequestMapping("/api/students")8public class StudentController {9 10 @GetMapping11 public String getAllStudents() {12 return "Returning all students";13 }14 15 @GetMapping("/{id}")16 public String getStudentById(@PathVariable int id) {17 return "Student ID: " + id;18 }19 20 @GetMapping("/hello")21 public String hello() {22 return "Welcome to Spring Boot REST API!";23 }24}Keywords
Explore the important concepts and keywords associated with this Java snippet.
💡 These tags help you quickly identify the concepts covered in this snippet and make it easier to discover similar Java solutions throughout the library.