@DeleteMapping

Learn how to delete a record from the database using DELETE request.

The HTTP DELETE request deletes a record. The primary key of the record to be deleted can be sent as part of the request URI or the record itself can be sent as part of the request body.

The client will send a DELETE request to our REST service with the id of the player to be deleted. The REST Service deletes the record and responds with the 200 (OK) status code to the client.

Press + to interact
DELETE request to /players/3
DELETE request to /players/3

JpaRepository inherits two methods of the CrudRepository for deleting a record. One is the delete() method and the other is deleteById() method. Both are used to remove entities from the database. The delete method takes an entity as its parameter and deletes it from the database. While, deleteById accepts the primary key of the entity to be deleted and removes the corresponding entity. They both have the same function, and internally, the deleteById() method typically calls the delete() method after finding the entity by its ID ...