Understanding @PathVariable and @RequestParam in Spring Boot

🌱 Day 4 of My Tech Journey — Understanding @PathVariable & @RequestParam in Spring Boot Today I explored how to send data through a REST API in Spring Boot using path parameters and query parameters. Here’s a simple example: @RestController @RequestMapping("/api") public class UserController { @GetMapping("/user/{id}") public String getUser(@PathVariable int id, @RequestParam(required = false) String name) { return "User ID: " + id + ", Name: " + name; } } 👉 Output: User ID: 10, Name: Harshita 🔑 Takeaway: @PathVariable is used to pass values inside the URL, while @RequestParam is used for query parameters. #SpringBoot #Java #RESTAPI #CodingJourney #BackendDevelopment

To view or add a comment, sign in

Explore content categories