liveBook · Manning

@putmapping

As explained in Spring in Action, Sixth Edition

@PutMapping is a Spring MVC annotation that maps HTTP PUT requests to a controller method.

@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

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains replacement semantics and handler responsibility, but stops short of Spring MVC internals.
Examples
Uses an order controller that replaces an order from JSON and contrasts it with field-by-field order patching.
What it assumes
Builds on HTTP method roles and JSON request handling, while demonstrating the mapping and persistence flow through an order example.
What you can do after
Apply it via Spring MVC to implement a complete-resource update endpoint backed by a repository.
How it connects
Connects HTTP PUT with REST services, controller methods, request bodies, repositories, and HTTP PATCH.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.