0
0
Spring Bootframework~5 mins

@PutMapping and @DeleteMapping in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @PutMapping annotation in Spring Boot?
The @PutMapping annotation maps HTTP PUT requests to a specific method in a controller. It is used to update existing resources on the server.
Click to reveal answer
beginner
What does the @DeleteMapping annotation do in a Spring Boot controller?
The @DeleteMapping annotation maps HTTP DELETE requests to a method. It is used to delete resources from the server.
Click to reveal answer
intermediate
How do @PutMapping and @DeleteMapping differ from @GetMapping and @PostMapping?
@PutMapping and @DeleteMapping handle updating and deleting resources, respectively, while @GetMapping retrieves data and @PostMapping creates new resources.
Click to reveal answer
intermediate
Show a simple example of a method using @PutMapping to update a user by ID.
Example:
@PutMapping("/users/{id}")
public ResponseEntity<User> updateUser(@PathVariable Long id, @RequestBody User user) {
  // update logic here
  User updatedUser = userService.updateUser(id, user);
  return ResponseEntity.ok(updatedUser);
}
Click to reveal answer
intermediate
Why is it important to use @DeleteMapping for delete operations instead of @GetMapping?
Using @DeleteMapping clearly signals the intent to delete a resource and follows HTTP standards. @GetMapping is meant for safe, read-only operations and should not change server state.
Click to reveal answer
Which HTTP method does @PutMapping handle?
AGET
BPOST
CDELETE
DPUT
What is the main use of @DeleteMapping in Spring Boot?
ATo create new resources
BTo delete resources
CTo retrieve resources
DTo update existing resources
Which annotation would you use to update a resource at the URL '/items/{id}'?
A@PutMapping("/items/{id}")
B@PostMapping("/items/{id}")
C@GetMapping("/items/{id}")
D@DeleteMapping("/items/{id}")
Which HTTP method should NOT be used to delete a resource?
ADELETE
BPUT
CGET
DPOST
In a Spring Boot controller, which annotation is best for a method that removes a user by ID?
A@DeleteMapping
B@PutMapping
C@PostMapping
D@GetMapping
Explain how @PutMapping and @DeleteMapping are used in a Spring Boot REST controller.
Think about how HTTP methods relate to resource actions.
You got /4 concepts.
    Describe why it is important to use the correct HTTP method annotations like @PutMapping and @DeleteMapping in REST APIs.
    Consider how clients and servers understand requests.
    You got /4 concepts.