Spring - @DeleteMapping and @PutMapping Annotation

Last Updated : 10 Mar, 2026

In Spring Boot, @PutMapping and @DeleteMapping are commonly used in controller classes to map HTTP PUT and DELETE requests to specific methods. These annotations make the code more readable and help implement RESTful CRUD operations efficiently.

@DeleteMapping Annotation

@DeleteMapping in Spring is used to handle HTTP DELETE requests in RESTful web services. It maps a specific URL to a controller method that deletes a resource from the server. It is a shortcut for @RequestMapping(method = RequestMethod.DELETE).

  • Used to delete a resource from the server.
  • Commonly used in REST APIs for removing records.

Example:

Java
@RestController
public class StudentController {

    @DeleteMapping("/students/{id}")
    public String deleteStudent(@PathVariable int id) {
        return "Student with ID " + id + " deleted successfully!";
    }
}

Explanation: the deleteStudent method is annotated with @DeleteMapping. It handles DELETE requests sent to /students/{id}. The student ID is passed as a path variable to delete the specific student.

@PutMapping annotation

@PutMapping is used to handle HTTP PUT requests in a REST API. It maps a request to a controller method that updates an existing resource on the server. This annotation is commonly used when a client sends updated data to modify existing records.

  • Used to handle HTTP PUT requests in Spring controllers.
  • Commonly used for updating existing resources in REST APIs.

Example:

Java
@RestController
@RequestMapping("/users")
public class UserController {

    @PutMapping("/{id}")
    public String updateUserName(@PathVariable int id, @RequestBody String name) {
        return "User with ID " + id + " updated with name " + name;
    }
}

Explanation: @PutMapping("/{id}") handles the HTTP PUT request to update a user's name. The @PathVariable annotation is used to get the user ID from the URL, while @RequestBody receives the new name sent in the request body. The method then processes the data and returns a confirmation message 

@DeleteMapping Vs @PutMapping Annotation

Feature@PutMapping@DeleteMapping
PurposeUsed to update an existing resource.Used to delete an existing resource.
HTTP MethodHandles HTTP PUT requests.Handles HTTP DELETE requests.
Data HandlingUsually receives updated data in the request body.Usually requires only the resource ID to delete it.
Example UseUpdating user details, product price, etc.Deleting a user, product, or record.
Example Annotation@PutMapping("/users/{id}")@DeleteMapping("/users/{id}")
Comment

Explore