The @PutMapping annotation maps HTTP PUT requests to a Spring MVC controller method. It is a shortcut for @RequestMapping(method = RequestMethod.PUT) and is used to replace or update an existing resource in a REST API. It works in both Spring MVC and Spring Boot applications and has been available since Spring 4.3.
PUT has defined semantics: it is idempotent, so sending the same request several times leaves the server in the same state as sending it once. Your handler should respect that.
@PutMapping is a composed annotation. These two declarations are equivalent:
It accepts the same attributes as @RequestMapping, such as value/path, consumes, produces, params and headers. The sibling annotations are @GetMapping, @PostMapping, @PatchMapping and @DeleteMapping.
How it works:
@PathVariable binds {id} from the URL.@RequestBody deserializes the JSON body with Jackson into the record.@Valid triggers Bean Validation (the jakarta.validation package in Spring Boot 3 and later). Invalid input produces a 400 response.Calling it:
| Method | Typical use | Idempotent |
|---|---|---|
POST | Create a resource, or run an action | No |
PUT | Replace a resource completely | Yes |
PATCH | Change only some fields | Not guaranteed |
DELETE | Remove a resource | Yes |
With PUT, the client sends the full representation. Fields that are missing are normally reset or rejected rather than left unchanged. If you only want to change a few fields, use @PatchMapping.
Return the status that tells the client what happened:
200 OK with the updated body, or 204 No Content with no body, when the update succeeded.404 Not Found when the id does not exist, unless your API allows PUT to create at a client-chosen URL, in which case return 201 Created.400 Bad Request for validation failures and 409 Conflict for version conflicts.415 Unsupported Media Type is returned automatically when consumes does not match the request content type.For concurrency, support optimistic locking with a version field or an If-Match ETag header, so that two clients cannot silently overwrite each other.
Centralize error mapping with @RestControllerAdvice, or return ProblemDetail (RFC 9457 style, supported by Spring since 6.0) from your exception handlers for consistent error bodies.
Browsers cannot submit PUT from plain HTML forms. For form posts, Spring offers HiddenHttpMethodFilter (enabled with spring.mvc.hiddenmethod.filter.enabled=true in Spring Boot), which reads a _method field. For JavaScript clients, use fetch with method: "PUT".
@PutMapping is a shortcut for @RequestMapping(method = RequestMethod.PUT). It is shorter and states the intent clearly.
Use PATCH for partial updates. PUT is defined as a full replacement of the resource.
Yes. Return ResponseEntity.noContent().build() or annotate the method with @ResponseStatus(HttpStatus.NO_CONTENT) and return void.
The URL matched a handler, but none accepts PUT for it. Check the path and that the method is annotated with @PutMapping. Also check that your security or CORS configuration allows PUT.
@PutMapping binds HTTP PUT requests to a handler method, which makes it the standard way to replace a resource in a Spring REST API. Combine it with @PathVariable, @Valid @RequestBody, correct status codes and optimistic locking, and keep the handler idempotent.