@PutMapping connects a Spring MVC controller method to HTTP PUT requests. PUT treats the submitted data as a replacement for the resource at the requested URL, so the request normally needs to contain the complete resource. section 7.1.3
For an order update, omitted properties are replaced with null, and omitted nested data such as tacos can be removed. Use PATCH instead when the client should change only selected properties. section 7.1.3
@PutMapping(path="/{orderId}", consumes="application/json")
public TacoOrder putOrder(
@PathVariable("orderId") Long orderId,
@RequestBody TacoOrder order) {
order.setId(orderId);
return repo.save(order);
}
This controller method accepts JSON at an order-specific path, obtains the order identifier from the URL, receives the replacement order in the request body, and saves it through the repository. section 7.1.3
@PutMapping specifies which requests a method handles; it does not implement the update itself. The handler must accept the complete data and persist the replacement, while a PATCH handler needs additional logic to merge selected fields. section 7.1.3
PUT and PATCH are both commonly used for updates, while POST is typically used to create resources. Choose the mapping according to the operation’s intended HTTP semantics. section 7.1.2
