DAY 1 observation 16/7/25

 tools description:

   language =>  java version 21 (LTS)

     ide     => eclipse 

Spring Boot => 

 

✅ What is @RestController?

 @RestController

It is a specialized version of @Controller that combines:

  • @Controller → Marks the class as a Spring MVC controller

  • @ResponseBody → Tells Spring to return data (like JSON/XML) instead of rendering a view

🔹 Purpose:

  • Used for REST APIs that return data, not HTML

  • Automatically serializes Java objects (like List, Map, or custom classes) to JSON (via Jackson)

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, World!";
    }
}
When you access http://localhost:8080/hello, it returns:

✅ What is @GetMapping

@GetMapping("/endpoint")

@RequestMapping(method = RequestMethod.GET, value = "/endpoint")


@GetMapping("/students")
public List<String> getStudents() {
    return List.of("Alice", "Bob", "Charlie");
}

🔹 Purpose:

  • Maps HTTP GET requests to a specific method

  • Annotation Purpose Used On Returns
    @RestController Marks a class as a REST controller On class Data (JSON/XML)
    @GetMapping Maps HTTP GET request to a method On method Response data (JSON)

    Commonly used to read/fetch data

     

    Annotation Description
    @PostMapping Maps HTTP POST requests
    @PutMapping Maps HTTP PUT requests
    @DeleteMapping Maps HTTP DELETE requests
    @RequestBody Maps the request JSON body to a POJO
    @PathVariable Gets a value from URL path
    @RequestParam Gets query parameters from the URL

     


 

Comments

Popular posts from this blog

INTRO OF SPRING BOOT

JAVA-INTO

STRUCTURE OF SPRING BOOT (Maven)