https://t.
me/itcoursesfree1/1256
1.
@PathVariable: Extracts values from the URI path and maps them to method
parameters.
1. @PathVariable:
Extracts values from the URI path and maps them to method parameters.
java
Copy
Edit
@GetMapping("/user/{id}")
public String getUserById(@PathVariable int id) {
return "User ID: " + id;
}
Request: GET /user/101
Response: "User ID: 101"
===================================================================================
=====================
2.
@RequestParam: Binds query parameters from the request to method parameters.
@RequestParam:
Binds query parameters from the request to method parameters.
@GetMapping("/search")
public String search(@RequestParam String keyword) {
return "Search result for: " + keyword;
}
Request: GET /search?keyword=Java
Response: "Search result for: Java"
===================================================================================
=====================
3. ..
@RequestBody: Maps the request body to a method parameter for data binding.
@RequestBody:
Maps the request body to a method parameter for data binding.
java
Copy
Edit
@PostMapping("/addUser")
public String addUser(@RequestBody User user) {
return "User added: " + user.getName();
}
{
"name": "Raghav",
"email": "[email protected]"
}
Response: "User added: Raghav"