@PatchMapping in Spring: Partial Updates with HTTP PATCH
@PatchMapping routes HTTP PATCH requests to controller methods for partial updates. See examples, JSON Merge Patch, validation and common pitfalls.
2,882 posts about Java: questions with answers, tutorials and articles, newest first.
@PatchMapping routes HTTP PATCH requests to controller methods for partial updates. See examples, JSON Merge Patch, validation and common pitfalls.
Use @DeleteMapping with @PathVariable to remove a resource in Spring MVC, return 204 or 404 correctly, and keep the endpoint idempotent, secure and tested.
@DeleteMapping is Spring's shortcut for handling HTTP DELETE requests in REST controllers. See attributes, response codes, security and a MockMvc test.
Use @PutMapping with @PathVariable and a validated @RequestBody to replace a resource, return the right status code, and keep partial updates in PATCH.
@PutMapping maps HTTP PUT requests to a Spring controller method for full resource updates. Includes a validated example, status codes and PUT versus PATCH.
Use @PostMapping to accept JSON, form submissions and file uploads in Spring MVC, validate input, return 201 Created and test the endpoint with MockMvc.
@PostMapping maps HTTP POST requests to controller methods in Spring MVC. See how to create resources, validate input, return 201 Created and handle form submissions.
Use @GetMapping to serve JSON or views in Spring MVC, bind path variables and query parameters, add cache headers and test the controller with MockMvc.
@GetMapping maps HTTP GET requests to Spring controller methods. See its attributes, how to bind path and query data, and how to test and design GET endpoints.
Define a Spring MVC controller with @Controller or @RestController, map requests with @GetMapping and friends, and handle input and errors cleanly.
@Controller declares a Spring MVC controller bean that handles web requests and returns view names. Learn how it works, how it differs from @RestController, and how to test it.
Use @ModelAttribute methods to add shared data to the Spring MVC model, preload entities and apply attributes globally with @ControllerAdvice.
Store and read per-user state in Spring Boot using HttpSession, @SessionAttributes and session-scoped beans, and share sessions across instances with Spring Session.
@SessionScope gives every HTTP session its own bean instance, ideal for carts and per-user state. See how the proxy, serialization and thread safety work.
Register global binders with @ControllerAdvice and shared converters with WebMvcConfigurer so every controller binds request data the same way.
WebDataBinder converts and validates request parameters in Spring MVC. See how to customise it with @InitBinder and protect your models from mass assignment.
Learn how to bind request data to your own types in Spring MVC using Converter, Formatter, @InitBinder and WebDataBinder, with security and error handling tips.
@InitBinder configures the WebDataBinder in Spring MVC. See how to scope it, register converters and formatters, and share rules with @ControllerAdvice.
Learn the ways to return HTTP status codes in Spring Boot, from ResponseEntity and @ResponseStatus to global exception handling with ProblemDetail.
Return files from Spring Boot using ResponseEntity and Resource, stream generated content, set Content-Disposition correctly and keep paths safe.