0% found this document useful (0 votes)
3 views1 page

Springbootanotations Controller

The document explains three key annotations in Spring Framework: @PathVariable, @RequestParam, and @RequestBody. @PathVariable extracts values from the URI path, @RequestParam binds query parameters, and @RequestBody maps the request body to method parameters. Each annotation is illustrated with example code and corresponding request and response scenarios.

Uploaded by

Raghav Khajuria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Springbootanotations Controller

The document explains three key annotations in Spring Framework: @PathVariable, @RequestParam, and @RequestBody. @PathVariable extracts values from the URI path, @RequestParam binds query parameters, and @RequestBody maps the request body to method parameters. Each annotation is illustrated with example code and corresponding request and response scenarios.

Uploaded by

Raghav Khajuria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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"

You might also like