Spring MVC - Handling HTTP PATCH Request

[Last Updated: Feb 23, 2018]

This example shows how to handle HTTP PATCH request in Spring MVC


PUT method creates/replaces the resource at the requested URI.

PATCH method modifies the existing resource (partially) at the requested URI.

POST method creates/modifies the resource without targeting an URI. After modification, how user can make use of the same resource, that's entirely dependent on the web application logic.


The controller

public class ArticleController {

  private ArticleService articleService;

  public String patchArticle(@RequestBody MultiValueMap<String, String> formParams) {
      long id = Long.parseLong(formParams.getFirst("id"));
      String content = formParams.getFirst("content");
      articleService.updateArticle(id, content);
      return "Article updated.";

  public String getArticle(@PathVariable("id") long id, Model model) {
      Article article = articleService.getArticleById(id);
      model.addAttribute("article", article);
      return "article-form";
public class Article {
  private long id;
  private String content;

  public Article(long id, String content) { = id;
      this.content = content;


    <script src=""></script>

<h3>Article Form</h3>
<form id="article-form">
         id: <input type="text" name="id" value="${}" readonly>
    content: <input type="text" name="content" value="${article.content}">
                  <input type="submit" value="Submit">
            var form = $(this);
            var id = form.find('input[name="id"]').val();
            var url = 'http://localhost:8080/articles/'+id;
            var content = form.find('input[name="content"]').val();
                type : 'PATCH',
                url : url,
                contentType: 'application/x-www-form-urlencoded',
                data : "id=" + id + "&content=" + content,
                success : function(data, status, xhr){
                  //refresh the current page
                error: function(xhr, status, error){


Java Config

public class MyWebConfig implements WebMvcConfigurer {

  public void configureViewResolvers(ViewResolverRegistry registry) {
      registry.jsp("/WEB-INF/views/", ".jsp");


To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war

Accessing http://localhost:8080/articles/1 :

Editing the content form field and submitting the form will refresh the form with updated content:

Example Project

Dependencies and Technologies Used:

  • spring-webmvc 5.0.3.RELEASE: Spring Web MVC.
  • javax.servlet-api 3.0.1 Java Servlet API
  • jstl 1.2 javax.servlet:jstl
  • JDK 1.8
  • Maven 3.3.9

PATCH Request Example Select All Download
  • spring-patch-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
          • webapp
            • WEB-INF
              • views

    See Also